Why does this kill Excel?

pcc

Well-known Member
Joined
Jan 21, 2003
Messages
1,353
I have this code in a userform module. There are severaL charts as objects in the "Charts" sheet. The userform has 'next' and 'previous' buttons. When they are pressed, the value of chartnum changes, and the next or previous chart is loaded to Image1 on the userform. This works fine, but if I repeatedly and rapidly press next or previous, Excel crashes. Anyone have any idea why this might be so?

Code:
Private Sub UpdateChart()
' chartnum is defined elsewhere in the module as an integer
    Set currentchart = Sheets("Charts").ChartObjects(ChartNum).Chart
    currentchart.Parent.Width = Image1.Width
    currentchart.Parent.Height = Image1.Height
'   Save chart as GIF
    fname = "D:\temp_chart\temp.gif"
    currentchart.Export Filename:=fname, FilterName:="GIF"
'   Show the chart
    Image1.Picture = LoadPicture(fname)
    Set currentchart = Nothing
  
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,203,255
Messages
6,054,403
Members
444,723
Latest member
Gagan sree ram

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