本文介绍了从Excel导出图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何从excel而不是使用Snipping工具导出图形...我发现了一些代码和.但是我仍然遇到以下错误:

I was wondering how to export graphs from excel instead of using Snipping tool ... I found some code there and there. But I remain stuck with the following error :

"Run-Time error '424'": Object required 

(与链接2相同),但我不知道它是从哪里来的.

(same as on link 2) but I can't figure out where does it come from ...

任何想法从哪里开始?

Any thoughts where to start by ?

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

推荐答案

您的代码中有几个错误,Option Explicit是一个很好的查找错别字的方法,正如几个人所说.

There were a couple of errors in your code Option Explicit is a great way to find typos as a couple people said.

另一个错误是您的myChart.Export (SaveToDirectory & myChart.Name & ".png", PNG)行.您不需要filterName,因此myChart.Export (SaveToDirectory & myChart.Name & ".png")在这种情况下完全可以

Another error was with on your myChart.Export (SaveToDirectory & myChart.Name & ".png", PNG) line. You do not need the filterName so myChart.Export (SaveToDirectory & myChart.Name & ".png") is perfectly ok for this occasion

完整代码:

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上运行,我会尽力帮助您

I have tested this code and it works on my pc if you get any issues i will try to help you out

希望这会有所帮助

这篇关于从Excel导出图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 16:30