Microsoft KB Archive/186220

= XL98: Excel Quits Unexpectedly Running Macro That Creates Chart =

Article ID: 186220

Article Last Modified on 10/10/2006

-

APPLIES TO


 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q186220





SYMPTOMS
If you use a Microsoft Visual Basic for Applications macro to create a chart, you may experience one or more of the following problems:

 Microsoft Excel 98 Macintosh Edition may unexpectedly quit. -or-

 You may have to restart your computer. -or-

 You may also receive an error message similar to the following:

The application "Microsoft Excel" has unexpectedly quit, because an error of type 1 occurred.

You should save your work in other open applications and restart the computer.





CAUSE
You may encounter the problems described in the "Symptoms" section if both of the following conditions are true:


 * You are using the xlLocationAsObject constant for the Where argument of the Location method. -and-


 * You are using an invalid string for the Name argument of the Location method.



WORKAROUND
To prevent this problem with your macro, use a valid worksheet name for the Name argument of the Location method.



STATUS
Microsoft has confirmed this to be a problem in Microsoft Excel 98 Macintosh Edition.



MORE INFORMATION
The following steps demonstrate how this problem occurs.

 Save and close all open workbooks, and then open a new workbook.</li> Enter the following in Sheet1:

A1: 1

A2: 2

A3: 3

</li> Press OPTION+F11 to start the Visual Basic Editor.</li> On the Insert menu, click Module.</li>  Enter the following code in the module: Sub AddChart Charts.Add ActiveChart.ChartType = xlColumnClustered ActiveChart.SetSourceData _ Source:=Sheets("Sheet1").Range("A1:A3"),PlotBy:=xlColumns

'At this point, the active sheet is a Chart sheet with a column chart 'and ActiveSheet.Name will return "Chart1" as a string value.

ActiveChart.Location _ where:=xlLocationAsObject, Name:=ActiveSheet.Name End Sub </li> On the File menu, click "Close and Return to Microsoft Excel".</li> On the File menu, click Save.</li> Press Option+F8, select AddChart in the list of macros, and then click Run.

NOTE: Microsoft Excel will unexpectedly quit.</li></ol>

To prevent this from occurring, follow these steps:

<ol> Restart Microsoft Excel.</li> Open the workbook you created in the previous list of steps.</li> Start the Visual Basic Editor (press Option+F11).</li>  Modify the AddChart macro so that the code looks like the following: Sub AddChart

mysheet=ActiveSheet.Name

Charts.Add ActiveChart.ChartType = xlColumnClustered ActiveChart.SetSourceData _ Source:=Sheets("Sheet1").Range("A1:A3"), PlotBy:=xlColumns

'At this point, the active sheet is a Chart sheet with a column chart 'and ActiveSheet.Name will return "Chart1" as a string value.

'Since the variable mysheet picks up the name of the activesheet 'before the chart sheet is created, you will not unexpectedly quit 'using the variable.

ActiveChart.Location _ where:=xlLocationAsObject, Name:=mysheet

End Sub </li></ol>

<div class="references_section">