1

I am trying to display an existing graph (Name: Chart 3) from Sheet3 to userform.

I used the below code, and it pops up error with debugging

Private Sub CommandButton1_Click()
Dim cchart As Chart
Dim fname As String


Set cchart = Sheets("Sheet3").ChartObjects("Chart 3").Chart
fname = "C:\CBS  Academic\Integrated Strategy Project\Final 
Paper\Temp\temp.gif"
cchart.Export Filename:=fname, filtername:="gif"
Image1.Picture = LoadPicture(fname)
End sub
4
  • check for correct sheet name chart name and fname (particularly fname in the code produced it is broken into 2 lines with out necessary " & _ ), i think it will work OK. Tried code with modified sheet and chart name and fname. found working without any error . Commented Jul 21, 2019 at 0:30
  • What is the error you're getting? Commented Jul 21, 2019 at 3:44
  • The compiler stops at the fourth line (Set cchart = Sheets("Sheet3").ChartObjects("Chart 3").Chart) Commented Jul 21, 2019 at 7:17
  • The error is that the object could not be found Commented Jul 21, 2019 at 7:18

1 Answer 1

1

Try this: (Tested)

Private Sub CommandButton1_Click()

Dim cchart As Chart
Dim fname As String
Set cchart = Sheets("Sheet3").ChartObjects("Chart 3").Chart

fname = "C:\CBS  Academic\Integrated Strategy Project\FinalPaper\Temp\temp.gif" 'check the address again

cchart.Export Filename:=fname, filtername:="gif"
Image1.Picture = LoadPicture(fname)

End sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.