gpt4 book ai didi

excel - 将图表导出为图像 - 只需单击按钮

转载 作者:行者123 更新时间:2023-12-01 18:41:33 24 4
gpt4 key购买 nike

我正在尝试创建一个按钮,将“图表”工作表中的图表导出为 jpeg 文件。这是我的代码,但它不断显示此错误:

runtime error 424: object required

专门为此:

Set myChart = Graphs.ChartObjects(3).Name = "Chart4"

这是代码

Sub ExportChart()
Dim myChart As Chart
Dim myFileName As String
Set myChart = Graphs.ChartObjects(3).Name = "Chart4"
myFileName = "myChart.jpg"
On Error Resume Next
Kill ThisWorkbook.Path & "\" & myFileName
myChart.Export Filename:=ThisWorkbook.Path & "\" & myFileName, Filtername:="PNG"
MsgBox "OK"
Set myChart = Nothing
End Sub

谢谢大家!

最佳答案

这就是你正在尝试的吗?

此外,如果您想将其另存为 jpg 那么为什么要使用 png 过滤器?我已将“myChart.jpg”更改为“myChart.png”。根据需要进行更改。

Sub ExportChart()
Dim objChrt As ChartObject
Dim myChart As Chart

Set objChrt = Sheets("Graphs").ChartObjects(3)
Set myChart = objChrt.Chart

myFileName = "myChart.png"

On Error Resume Next
Kill ThisWorkbook.Path & "\" & myFileName
On Error GoTo 0

myChart.Export Filename:=ThisWorkbook.Path & "\" & myFileName, Filtername:="PNG"

MsgBox "OK"
End Sub

关于excel - 将图表导出为图像 - 只需单击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11939087/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com