Microsoft KB Archive/157311

= XL97: Problems with Recorded Macro That Creates Map Object =

Article ID: 157311

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 97 Standard Edition

-



This article was previously published under Q157311





SYMPTOMS
When you record a macro that embeds a Microsoft Map object in a worksheet, the following problems may occur when you run the macro:

 The position and size of the map differs from the map you created when you recorded the macro. -and- You receive the following error message:

Run-time error '1004':

Method 'CutCopyMode' of Object '_Application' failed.





WORKAROUND
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 professionals 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 a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

To work around this problem, modify the macro to set the proper coordinates for the map object and remove the CutCopyMode method. The following steps illustrate how to record and modify a macro that embeds a Microsoft Map object on your worksheet.

Recording the Macro
 In Microsoft Excel, open a new workbook.  In cells A1:B2 on Sheet1, type the following:      A1: Mexico     B1: 100 A2: Canada    B2: 150  On the Tools menu, point to Macro, and click Record New Macro. Type CreateMap in the "Macro name" box, and click OK to start recording.</li> Select cells A1:B2.</li> On the Insert menu, click Map. Draw the map object on the worksheet.</li> Select cell A1 on the worksheet to deactivate the map object.</li> On the Tools menu, point to Macro and click Stop Recording.</li></ol>

Modifying the Macro
<ol>  On the Tools menu, point to Macro and click Macros. Select the Createmap macro and click Edit.

The CreateMap macro appears in the Code window in the Visual Basic Editor. It will look similar to the following example: Sub CreateMap

Range("A1:B2").Select Range("B2").Activate ActiveSheet.OLEObjects.Add(ClassType:="MSMap.8", Link:=False, _             DisplayAsIcon:=False, Left:=3.75, Top:=9, Width:=3.75, _              Height:=9).Activate Application.CutCopyMode = False Range("A1").Select End Sub </li>  Modify the macro such that the modified macro looks like the following example: Sub CreateMap

Range("A1:B2").Select Range("B2").Activate ActiveSheet.OLEObjects.Add(ClassType:="MSMap.8", Link:=False, _             DisplayAsIcon:=False, Left:=50, Top:=50, Width:=200, _              Height:=160).Activate Range("A1").Select End Sub Notice that you change the arguments for the Add method for the OLEObjects collection to indicate the coordinates and size of the data map. Additionally, you must remove the Application.CutCopyMode = False line. </li> On the File menu, click "Close and Return to Microsoft Excel".</li></ol>

To run the macro, activate Sheet1, point to Macro on the Tools menu, click Macros, select the macro "CreateMap" and click Run.

<div class="status_section">

STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.

Additional query words: XL97 8.0 8.00 datamap

Keywords: kbbug kbdtacode kberrmsg kbpending KB157311

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.