我想知道如何从excel而不是使用Snipping工具导出图形...我发现了一些代码there和there。但是我仍然遇到以下错误:
"Run-Time error '424'": Object required
任何想法从哪里开始?
Sub SaveAllCharts()
Dim SaveToDirectory As String
Dim myChart As Chart
SaveToDirectory = ActiveWorkbook.Path & "\Images\"
MsgBox ("Saved Directory:" + SaveToDirectory)
For Each myChart In ActiveWorkbok.Charts MsgBox (OK) myChart.Export SaveToDirectory & myChart.Name & ".png", PNG Next
End Sub
答案 0 :(得分:0)
您的代码Option Explicit
中有几个错误,就像几个人所说的那样,是查找错字的好方法。
您的myChart.Export (SaveToDirectory & myChart.Name & ".png", PNG)
行上还有另一个错误。您不需要filterName,因此myChart.Export (SaveToDirectory & myChart.Name & ".png")
在这种情况下完全可以
完整代码:
Option Explicit
Sub SaveAllCharts()
Dim SaveToDirectory As String
Dim myChart As Chart
SaveToDirectory = ActiveWorkbook.Path
MsgBox ("Saved Directory:" + SaveToDirectory)
For Each myChart In ActiveWorkbook.Charts
myChart.Export (SaveToDirectory & myChart.Name & ".png")
Next myChart
End Sub
我已经测试了此代码,如果您遇到任何问题,它将在我的PC上运行,我会尽力帮助您
希望这会有所帮助