XL97: Error Appears When Changing Chart Location with a MacroLast reviewed: January 9, 1998Article ID: Q169250 |
The information in this article applies to:
SYMPTOMSWhen you use a macro to change a chart that is on a chart sheet to a chart object on a worksheet (or vice versa), you receive one of the following error messages:
Run-time error '-2147221080 (800401a8)': Automation error -or- This program has performed an illegal operation and will be shut down. If the problem persists, contact the program vendor.If you click Details, the following error message appears:
EXCEL caused an invalid page fault in module MSO97.DLL at 0137:307e034e.If you click Close, Microsoft Excel 97 closes.
CAUSEThis problem occurs when you create a Visual Basic for Applications macro and both of the following conditions are true:
WORKAROUNDSMicrosoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400. To move a chart without receiving this error message, use one of the following methods.
Method 1: Refer to the Chart as an ObjectAssign 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 ActiveChartIf 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" STATUSMicrosoft 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 INFORMATIONYou 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 REFERENCESFor more information about the Location method, click the Index tab in Help, type the following text
location methodand then double-click the selected text to go to the "Location Method" topic.
|
Additional query words: XL97 gpf ipf ole automation
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |