Excel の VBA 機能を利用して 【図として保存する 】マクロを組みました。 ファイル名にはタイムスタンプを入力して保存する仕組みにしていますが、
Excel の VBA 機能を利用して 【図として保存する 】マクロを組みました。 ファイル名にはタイムスタンプを入力して保存する仕組みにしていますが、 ファイル名を手動入力させるダイアログを表示させることは可能でしょうか? 以下、現在のコードです Sub png画像保存() ActiveSheet.Previous.Select With ActiveWorkbook.ActiveSheet .Activate With .Shapes If .Count >= 2 Then .SelectAll Selection.Group.Name = "png画像" Else .SelectAll Selection.Name = "png画像" End If End With End With On Error Resume Next With ActiveSheet.Shapes("png画像") .CopyPicture ActiveSheet.ChartObjects.Add(0, 0, .Width, .Height).Name = "貼付用" End With With ActiveSheet.ChartObjects("貼付用") .Chart.PlotArea.Fill.Visible = msoFalse .Chart.ChartArea.Fill.Visible = msoFalse .Chart.ChartArea.Border.LineStyle = 0 End With Application.OnTime Now + TimeValue("00:00:01"), "sample2" End Sub Private Sub sample2() Dim mysn As String mysn = ActiveSheet.Name On Error GoTo ErrorHandler With ActiveSheet.ChartObjects("貼付用") .Chart.Paste .Chart.Export myImagePath & "ディレクトリ" & Format(Now(), "yyyymmdd-hhmmss") & ".png" .Delete MsgBox "保存しました。" ActiveSheet.Shapes.Range(Array("png画像")).Select Selection.Delete ActiveSheet.Next.Select Exit Sub ErrorHandler: MsgBox "画像がないので保存されません" ActiveSheet.Next.Select ActiveWorkbook.Save End With End Sub Function myImagePath() Dim MyWSH As Object Set MyWSH = CreateObject("WScript.Shell") myDeskTopPath = MyWSH.SpecialFolders("ディレクトリ") Set MyWSH = Nothing End Function なお、シートにNext,Previousが含まれているのは、隣接シートに画像を生成する 別のマクロがあり、画像を表示するシートと別にしているためです。 ご教示よろしくお願いします。
Visual Basic | Excel・45閲覧・50