XL98: Program Stops Responding Moving Chart Location Using Macro

Last reviewed: February 6, 1998
Article ID: Q180608
The information in this article applies to:
  • Microsoft Excel 98 Macintosh Edition

SYMPTOMS

When you use a macro to change a chart that is on a chart sheet to a chart object on a worksheet (or vice versa), the program stops responding (hangs) and you must restart your computer.

CAUSE

This problem occurs when you create a Microsoft Visual Basic for Applications macro and both of the following conditions are true:

  • You use the Location method to move a chart from one sheet to a second sheet, and then use this method to move the chart to a third location (or to the original location).

    For example, the following macro statement uses the Location method to move a chart to a chart sheet named Chart1:

          ActiveChart.Location where:=xlLocationAsNewSheet, Name:="Chart1"
    

        -and-
    
  • You use the Set statement to assign a variable to the chart object you want to move.

WORKAROUNDS

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp

To move a chart without receiving this error message, use one of the following methods.

Method 1: Refer to the Chart as an Object

Assign an object variable to the chart object each time it is moved. You must use this variable when you refer to the chart. For example, the following macro creates an embedded chart on Sheet1 using data on Sheet1 in the range A1:C4. The chart is moved to a new chart sheet and is then moved back to Sheet1. In the following example, each time the chart object is referenced, the variable x is set equal to the chart:

   Sub MoveChart()

      Dim x As Chart

      ' Create an embedded chart on a chart sheet.
      Set x = Charts.Add
      x.ChartType = xlColumnClustered
      x.SetSourceData Source:=Sheets("Sheet1").Range("A1:C4")
      Set x = x.Location(where:=xlLocationAsObject, Name:="Sheet1")
      ' Move chart to new sheet and reset the chart object variable x.
      Set x = x.Location(where:=xlLocationAsNewSheet, Name:="Chart1")
      ' Move chart to back to the chart sheet.
      Set x= x.Location(where:=xlLocationAsObject, Name:="Sheet1")

   End Sub

Method 2: Refer to the Chart as ActiveChart

If it is not necessary to assign an object variable to the chart, refer to the chart as ActiveChart. For example, the following macro statement uses the ActiveChart property and Location method to move a chart to a chart sheet named Chart1:

   ActiveChart.Location where:=xlLocationAsNewSheet, Name:="Chart1"

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

You can move a chart to a new location in Visual Basic for Applications by using the Location method. The first argument, Where, designates the location to which you want to move the chart. The valid locations and their associated XlChartLocation constants are listed in the following table.

   Location            Constant
   ----------------------------------------

   Chart sheet         XlLocationAsNewSheet
   Chart sheet         XlLocationAutomatic
   Worksheet object    XlLocationAsObject

REFERENCES

For more information about the Location method, click the Office Assistant in the Visual Basic Editor, type "location method" (without the quotation marks), click Search, and then click to view the "Location method" topic. topic.


Additional query words: XL98 crash lock freeze ole automation
Keywords : xlchart xlvbainfo
Version : MACINTOSH:98
Platform : MACINTOSH
Issue type : kbprb
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 6, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.