Export range as image does not work

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
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Pepito_child

New Member
Joined
Feb 13, 2016
Messages
49
Dear John, I thank you so much for your support! It worked, now the image is filled with the data from specified range.

I wish you all the best!
 

Watch MrExcel Video

Forum statistics

Threads
1,129,483
Messages
5,636,596
Members
416,927
Latest member
BNM8V6

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top