XL97: Excel Quits Unexpectedly Running Macro That Creates Chart
ID: Q186219
|
The information in this article applies to:
-
Microsoft Excel 97 for Windows
SYMPTOMS
If you use a Microsoft Visual Basic for Applications macro to create a
chart, you may receive one of the following errors:
In Windows 95
This program has performed an illegal operation and will be shut
down. If the problem persists, contact the program vendor.
If you click Details, you receive an error message similar to the
following:
EXCEL caused an invalid page fault in module Excel.exe at
0137:30118912.
In Windows NT
An application error has occurred and an application log is being
generated.
EXCEL.exe
Exception: access violation(0xc0000005), Address: 0x30125a30
After displaying the error messages, Microsoft Excel 97 for Windows quits.
CAUSE
You may encounter the problem 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 97 for
Windows. This problem no longer occurs in Microsoft Excel 2000.
MORE INFORMATION
The following steps demonstrate how this problem occurs.
- Save and close all open workbooks, and then open a new workbook.
- Enter the following in Sheet1:
A1: 1
A2: 2
A3: 3
- Press ALT+F11 to start the Visual Basic Editor.
- On the Insert menu, click Module.
- 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
- On the File menu, click "Close and Return to Microsoft Excel."
- On the File menu, click Save.
- Press ALT+F8, select AddChart in the list of macros, and then click
Run.
NOTE: Microsoft Excel will unexpectedly quit.
To prevent this from occurring, follow these steps:
- Restart Microsoft Excel.
- Open the workbook you created in the previous list of steps.
- Press ALT+F11 to start the Visual Basic Editor.
- Modify the AddChart macro, so that it is similar to the following macro:
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
REFERENCES
For more information about the Location Method, from the Visual Basic
Editor, click the Office Assistant, type location method, click Search,
and then click to view "Location Method."
NOTE: If the Assistant is hidden, click the Office Assistant button on the
Standard toolbar. If the Assistant is not able to answer your query, please
see the following article in the Microsoft Knowledge Base:
Q176476
OFF: Office Assistant Not Answering Visual Basic Questions
Additional query words:
XL97 hang lockup freeze lock up
Keywords : kbprg kbdta OffVBA KbVBA
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbbug