我很难找到从图表工作表中导出图表的正确语法,而不是嵌入在工作表中。我曾经嵌入过图表,但是应用户的要求将其转移到了自己的表格中,我似乎找不到合适的东西。这是嵌入式图表的代码,有人可以给我一个关于语法的提示吗?
Public Sub ExportChart()
Dim varChartObject As ChartObject
Dim varChart As Chart
Dim varFilename As String
Dim varPath As String
Set varChartObject = Sheets("Output Chart").ChartObjects(1)
Set varChart = varChartObject.Chart
varFilename = Format(ThisWorkbook.Sheets("Parameters").Range("C5").Value, "YYYYMMDD")
varPath = "MyPath\" & Format(ThisWorkbook.Sheets("Parameters").Range("C5").Value, "MM. MMMM")
On Error Resume Next
Kill varPath & "\" & varFilename
On Error GoTo 0
varChart.Export Filename:=varPath & "\" & varFilename & ".png", Filtername:="PNG"
Set varChartObject = Nothing
Set varChart = Nothing
End Sub
提前致谢
答案 0 :(得分:2)
您只需在开始时使用此功能:
Set varChart = Charts("chart sheet name")