Simple chart error 438

Viking31

New Member
Joined
Sep 19, 2018
Messages
2
Hello,

I know my error must be easy to spot, but I've tried everything I know. I literally only have a command button and an Image in the Form and a simple graph in Excel. I want my "1 Gráfico" chart to appear in Image1 when I press the button (I'm spanish, that's why it's called like that :) ), but I get error 438 in the chartObject line, please help!

Code:
Private Sub CommandButton1_Click()
Dim fname As String
Dim cchart As Chart
Set cchart = Worksheets("Hoja1").ChartObject("1 Gráfico").Chart
fname = "G:/temp.gif"
cchart.Export Filename = fname, Filtername:="gif"


Image1.Picture = LoadPicture(fname)
End Sub

Thank youuu
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Welcome to the forum!

Use ChartObjects, e.g.:
Code:
Private Sub CommandButton1_Click()  Dim fname As String
  Dim cchart As Chart
  
  'Set cchart = Worksheets("Hoja1").ChartObject("1 Gráfico").Chart
  Set cchart = Worksheets("Sheet1").ChartObject[COLOR="#FF0000"]s[/COLOR]("Chart 1").Chart
  
  'fname = "G:/temp.gif"
  fname = "c:\temp\temp.gif"
  cchart.Export Filename:=fname, Filtername:="gif"
  
  Image1.Picture = LoadPicture(fname)
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,265
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top