XL98: Excel Quits Unexpectedly Running Macro That Creates Chart

ID: Q186220

The information in this article applies to:

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:

CAUSE

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

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.

1. Save and close all open workbooks, and then open a new workbook.

2. Enter the following in Sheet1:

    A1: 1
    A2: 2
    A3: 3

3. Press OPTION+F11 to start the Visual Basic Editor.

4. On the Insert menu, click Module.

5. 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

6. On the File menu, click "Close and Return to Microsoft Excel".

7. On the File menu, click Save.

8. Press Option+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:

1. Restart Microsoft Excel.

2. Open the workbook you created in the previous list of steps.

3. Start the Visual Basic Editor (press Option+F11).

4. 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

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:

   ARTICLE-ID: Q176476
   TITLE     : OFF: Office Assistant Not Answering Visual Basic Questions

Additional query words: XL98 freeze hang lock up
Keywords          : kbprg kbdta OffVBA 
Version           : MACINTOSH:98
Platform          : MACINTOSH
Issue type        : kbbug
Solution Type     : kbpending

Last Reviewed: May 18, 1999