Pepito_child
New Member
- Joined
- Feb 13, 2016
- Messages
- 49
Hello everyone,
I kindly ask for your suppor!
I have an userform which includes a button that export the range as a image file. The following vba code worked very well at the beginning but now it send a blank image to the desktop. How should I solve this issue?
Thank you in advance!
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.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 your suppor!
I have an userform which includes a button that export the range as a image file. The following vba code worked very well at the beginning but now it send a blank image to the desktop. How should I solve this issue?
Thank you in advance!
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.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