Pepito_child
New Member
- Joined
- Feb 13, 2016
- Messages
- 49
Hello everyone,
I kindly ask for some support here.
How could the below export image code be changed so it would save the file's name from a specified cell, e.g. Cell M2?
Thank you in advance for your support!
Sub ExportImage()
Dim sFilePath As String
Dim sView As String
sView = ActiveWindow.View
ActiveWindow.View = xlNormalView
Application.ScreenUpdating = False
Set Sheet = ActiveSheet
sFilePath = CreateObject("WScript.Shell").specialfolders("Desktop") & "\" & ActiveSheet.Name & ".png"
zoom_coef = 300 / Sheet.Parent.Windows(1).Zoom
Set area = Sheet.Range("M1:X27")
area.CopyPicture xlPrinter
Set chartobj = Sheet.ChartObjects.Add(0, 0, area.Width * zoom_coef, area.Height * zoom_coef)
chartobj.Activate
chartobj.Chart.Paste
chartobj.Chart.Export sFilePath, "png"
chartobj.Delete
ActiveWindow.View = sView
Application.ScreenUpdating = True
MsgBox ("Export completed! The file can be found here:" & Chr(10) & Chr(10) & sFilePath)
End Sub
I kindly ask for some support here.

How could the below export image code be changed so it would save the file's name from a specified cell, e.g. Cell M2?
Thank you in advance for your support!
Sub ExportImage()
Dim sFilePath As String
Dim sView As String
sView = ActiveWindow.View
ActiveWindow.View = xlNormalView
Application.ScreenUpdating = False
Set Sheet = ActiveSheet
sFilePath = CreateObject("WScript.Shell").specialfolders("Desktop") & "\" & ActiveSheet.Name & ".png"
zoom_coef = 300 / Sheet.Parent.Windows(1).Zoom
Set area = Sheet.Range("M1:X27")
area.CopyPicture xlPrinter
Set chartobj = Sheet.ChartObjects.Add(0, 0, area.Width * zoom_coef, area.Height * zoom_coef)
chartobj.Activate
chartobj.Chart.Paste
chartobj.Chart.Export sFilePath, "png"
chartobj.Delete
ActiveWindow.View = sView
Application.ScreenUpdating = True
MsgBox ("Export completed! The file can be found here:" & Chr(10) & Chr(10) & sFilePath)
End Sub