Macro Errors May Occur if an Object Is Currently Selected

Last reviewed: November 2, 1994
Article ID: Q72137

SUMMARY

An error might be encountered in a macro if you attempt to manipulate the worksheet after selecting an object. A dialog box displays, stating that there is an error in the macro at the cell where the command tries to adjust the worksheet.

MORE INFORMATION

For example, the following macro selects a button on a worksheet and then attempts to adjust the row heights of a selected range. The macro will generate an error at cell A3.

   A1: =SELECT("button 1")
   A2: =FORMAT.SIZE(72,36,!C5)
   A3: =ROW.HEIGHT(0,"r15:r20")
   A4: =RETURN()

However, if you place the command in A3 to run first, the macro will run correctly. Another workaround is to follow the Select command with a second Select command that selects any cell on the worksheet.

   A1: =ROW.HEIGHT(0,"r15:r20")
   A2: =SELECT("button 1")
   A3: =FORMAT.SIZE(72,36,C5)
   A4: =RETURN()

   -or-

   A1: =SELECT("button 1")
   A2: =FORMAT.SIZE(72,36,C5)
   A3:= SELECT(!A1)
   A4: =ROW.HEIGHT(0,"R15:R20")
   A5: =RETURN()

This error occurs because objects are on a different layer than the worksheet layer. Although the worksheet is the active document, the object layer is the active layer when the worksheet manipulation is attempted. Other commands may also cause macro errors if attempted when an object is the current selection. Some commands, such as the Formula command will work fine.

REFERENCES

"Microsoft Excel Function Reference." Version 3.00, pages 210, 211.


KBCategory: kbother
KBSubcategory:

Additional reference words: noupd


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: November 2, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.