loading chart into a picture in a form vbaexcel

LuisVilarMoreira

New Member
Joined
Feb 15, 2018
Messages
19
Office Version
  1. 2016
Platform
  1. Windows
Hello everybody
I need your help with a problem

I have this code
VBA Code:
        Sheets("graficos").ChartObjects("g_gts_dp").Activate
        ActiveChart.ChartArea.Select
        ActiveChart.ChartArea.Copy
 
        Set Grafico = Sheets("graficos").ChartObjects("g_gts_dp").Chart
        ArquivoGIF = ThisWorkbook.Path & "\temp.gif"
        Grafico.Export Filename:=ArquivoGIF, FilterName:="GIF"
        Image1.Picture = LoadPicture(ArquivoGIF)

The code works, but only occasionally I get an error

- Run-time error '481':
Invalide picture

When a make "Debug" it will go to
Code:
Image1.Picture = LoadPicture(ArquivoGIF)

Thank a lot
Regard
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
It could come from you trying to overwrite an image file that is currently being referenced in your own document.

Try to null the image reference ( original code found here )
VBA Code:
With Image1
  If .Picture Is Nothing Then             ' picture property has been cleared already
     .Picture = LoadPicture(sImgName)
  Else                                    ' a picture is already displayed
     .Picture = LoadPicture(vbNullString) ' clear it now
  End If
End With

or reference another image in the Image1 before saving over the 'temp.gif' to free up the file.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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