I'm trying to create a button that would export a chart in sheet "Graphs" as a jpeg file. This is the code I have, however it keeps on showing this error:
runtime error 424: object required
Specifically for this:
Set myChart = Graphs.ChartObjects(3).Name = "Chart4"
And here's the code
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
Thanks everyone!
See Question&Answers more detail:os