- Jan 21, 2003
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?
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