Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel图形导出为空_Excel_Vba - Fatal编程技术网

Excel图形导出为空

Excel图形导出为空,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 = Activ

下面代码的目的是将图形图像导出到文件夹。当一步一步地使用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 

代码对我来说很好。请粘贴图表的截图好吗?非常感谢您抽出时间查看代码。我现在添加了截图。但我不确定这会有多大帮助。。。