Sulprobil
Search…
sbExportRange2Picture
Use this sub if you need to export a worksheet range into a jpg file.
I found this is one of the most convenient ways to present Excel results in a PowerPoint presentation. Thanks to my colleague Ashish P. I could change xlScreen to xlPrinter which will avoid the program to fail in some cases.
Please read my Disclaimer
1
Sub sbExportRange2Picture(sPath As String, rngInput As Range)
2
'Export range as image
3
'Change History:
4
'Version Excel Date Programmer Change
5
'1 2010 03/06/2017 Bernd Create
6
'2 2010 11/07/2017 Bernd Change xlScreen to xlPrinter
7
'3 2016 01/06/2020 Bernd Tested. Works.
8
9
Dim chtObj As ChartObject
10
11
rngInput.CopyPicture Appearance:=xlPrinter, Format:=xlPicture
12
Set chtObj = ActiveSheet.ChartObjects.Add(100, 30, 400, 250)
13
chtObj.Name = "TemporaryPictureChart"
14
chtObj.Width = rngInput.Width
15
chtObj.Height = rngInput.Height
16
17
'I hate to activate anything. Maybe the variant below is a better way
18
chtObj.Activate
19
ActiveChart.Paste
20
ActiveChart.Export Filename:=sPath, FilterName:="jpg"
21
22
chtObj.Delete
23
24
End Sub
Copied!
sbExportRange2Picture.xlsm
22KB
Binary
Last modified 10mo ago
Copy link