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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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!
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

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
Back
Top