如何通过名称引用导出图表 [英] How to export Chart via name reference
问题描述
我的一张表(图表)上有几个图表,我只想导出6个特定的图表。当我选择一个图表并且转到布局
选项卡时,我看到一些名为图表名称
的东西,图表名称。我试图将其中一个图表的名称更改为ChartA。请帮助这个简单的VBA代码。
I have several charts on one of my sheets (charts) and I only want to export 6 specific charts. When I select a chart and go to the Layout
tab I see something called Chart Name
which I assume lets me choose the chart name. I've tried changing the name to "ChartA" for one of the charts. Please help with this simple VBA code.
Sub SaveJPGTest()
Chart("ChartA").Export "Z:\specialChart.jpg"
End Sub
推荐答案
添加了 basePath
将jpg保存在与excel文件相同的目录中。保存为PNG,因为它似乎比JPG更好的质量和更小的文件大小。不知道这是否是最好的文件格式,但使用。
Added basePath
to save the jpg in the same directory as the excel file. Saved as a PNG because it seems to be better quality and smaller file size than JPG. Not sure if this is the best file format to use though.
此代码设置图表图表
和图表 ChartA
,然后保存活动图表。
This code sets sheet charts
and chart ChartA
active, then saves the active chart.
Sub SaveAreaPowerJPGs()
Dim basePath As String
basePath = ThisWorkbook.Path & "\"
ActiveWorkbook.Sheets("charts").Activate
ActiveSheet.ChartObjects("ChartA").Activate
ActiveChart.Export Filename:=basePath & "ChartA.jpg", Filtername:="PNG"
End Sub
这篇关于如何通过名称引用导出图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!