Excel图形导出为空

时间:2018-10-18 08:23:21

标签: excel vba excel-vba

以下代码的目的是将图形图像导出到文件夹。逐步使用F8时,它可以完美运行,但是正常执行时,图像变为空白。没有错误讯息。任何想法如何解决?任何帮助表示赞赏。

Sub ExportImage()

Dim sFilePath As String
Dim sView As String
Set Sheet = ThisWorkbook.Sheets("chart$")
sFilePath = "C:\temp\Chart.png"

Sheet.Select
sView = ActiveWindow.View
ActiveWindow.View = xlNormalView
zoom_coef = 100 / Sheet.Parent.Windows(1).Zoom

Set area = Sheet.Range(Sheet.PageSetup.PrintArea)
area.CopyPicture xlPrinter
Set chartobj = Sheet.ChartObjects.Add(0, 0, area.Width * zoom_coef, area.Height * zoom_coef)
chartobj.Chart.Paste
Application.ScreenUpdating = True
chartobj.Chart.Export sFilePath, "png"
chartobj.Delete

ActiveWindow.View = sView

MsgBox ("Export completed! The file can be found here:" & Chr(10) & Chr(10) & sFilePath)

End Sub 

![Output when doing step-by-step (F8) output when running macro (f5)

0 个答案:

没有答案
相关问题