The code below (1) locates the Temp folder on the user's system, and (2) exports the print range of a worksheet to a JPG image, then saves the image to the Temp folder.
The code works exactly as intended on my own system. On the user's system a JPG image is generated and saved, but the image comes up blank. Somehow it fails to capture anything from the worksheet.
My system runs Excel 2010, the user runs Excel 2016, but I have no idea whether the version difference matters. Has anyone encountered this issue before?
The code works exactly as intended on my own system. On the user's system a JPG image is generated and saved, but the image comes up blank. Somehow it fails to capture anything from the worksheet.
My system runs Excel 2010, the user runs Excel 2016, but I have no idea whether the version difference matters. Has anyone encountered this issue before?
Code:
Sub ExportImage()
Dim FSO As Object, TmpFolder As Object
Set FSO = CreateObject("scripting.filesystemobject")
Set TmpFolder = FSO.GetSpecialFolder(2)
SavePath = TmpFolder & "\Some Filename.jpg"
'Export print area as correctly scaled jpg image
With ThisWorkbook.Sheets("Some Worksheet")
zoom_coef = 100 / .Parent.Windows(1).Zoom
Set area = .Range(.PageSetup.PrintArea)
area.CopyPicture xlPrinter
Set chartobj = .ChartObjects.Add(0, 0, area.Width * zoom_coef, area.Height * zoom_coef)
chartobj.Chart.Paste
chartobj.Chart.Export SavePath, "jpg"
chartobj.Delete
End With
End Sub