これは
選択したセル範囲をPNG画像として保存するだけの、ちょっとしたExcelマクロです。
コード
'参照設定:
' Microsoft Scripting Runtime
' Windows Script Host Object Model
Function RangeToPng(r As Range, Optional fn As String = vbNullString)
With New FileSystemObject
If fn = vbNullString Then fn = .BuildPath(DesktopFolder, Replace(.GetTempName, "tmp", "png"))
End With
With New Excel.Application
With .Workbooks.Add
With .Worksheets(1).ChartObjects.Add(0, 0, r.Width, r.Height).Chart
r.CopyPicture
.Paste
.Export fn, "png"
End With
.Close False
End With
.Quit
End With
End Function
Private Function DesktopFolder()
With New WshShell
DesktopFolder = .SpecialFolders("Desktop")
End With
End Function
使用例
Sub セル範囲を画像にする()
Dim fn As String
RangeToPng ActiveWindow.RangeSelection, fn
MsgBox fn
End Sub