XL97: Macro Error Using Show Method with AutoShape Selected

Last reviewed: July 2, 1997
Article ID: Q166143
The information in this article applies to:
  • Microsoft Excel 97 for Windows

SYMPTOMS

In Microsoft Excel 97, if you run a Visual Basic for Applications macro that attempts to display the Format AutoShape dialog box, you may receive the following error message:

   Run-time error '1004':
   Show method of Dialog class failed

Or, the Format AutoShape dialog box may simply fail to appear, and you do not receive an error message.

The same macro works correctly in earlier versions of Microsoft Excel, and works occasionally in Microsoft Excel 97.

CAUSE

You may receive the aforementioned error message if both of the following are true:

  • Your macro contains a line of code similar to either of the following:

          Application.Dialogs(xlDialogPatterns).Show
    

          Application.ExecuteExcel4Macro ("PATTERNS?()")
    

    -and-

  • An AutoShape is selected when the above line of code is executed.

WORKAROUND

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

The xlDialogPatterns dialog box is not available for use with new drawing objects and AutoShapes in Microsoft Excel 97. However, it may be possible in some cases to display the Format AutoShape dialog box by using a line of code similar to the following:

   Sub Test1()
       SendKeys "^1", True
   End Sub

If the drawing object or AutoShape is selected when this line of code is executed, the Format AutoShape dialog box will be displayed, and you can format the AutoShape. When you click OK or Cancel, the macro will continue.

If you have not renamed any of your drawing objects or AutoShapes, you can use code similar to the following to display the correct dialog box:

   Sub Test2()

       'If the name of the drawing object begins with "AutoShape", then...
       If Left(Selection.Name, 9) = "AutoShape" Then

           '...use SendKeys to display the dialog box.
           SendKeys "^1", True

       'Otherwise, use the traditional method.
       Else
           Application.Dialogs(xlDialogPatterns).Show

       End If

   End Sub

Note that these methods may not always work, since it is not always possible to guarantee that the sent keys will produce the desired result. Note also that the SendKeys method is not available in Microsoft Excel for the Macintosh.

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

AutoShapes are a group of ready-made shapes that include such basic shapes as rectangles and circles, plus a variety of lines and connectors, block arrows, flowchart symbols, stars and banners, and callouts. The AutoShapes that may cause the problem described above are most of those found on the AutoShapes menu of the Drawing toolbar. This includes AutoShapes from the following submenus:

   Connectors
   Basic Shapes
   Block Arrows
   Flowchart
   Stars and Banners
   Callouts

NOTE: Not all of the Basic Shapes generate the error message.

REFERENCES

For more information about using the Built-in Dialogs, click the Office Assistant, type "built-in dialogs" (without quotation marks), click Search, and then click to view the "Built-In Dialog Box Argument List" topic.


Keywords : kbcode kberrmsg kbprg xlvbainfo
Version : 97
Platform : WINDOWS
Issue type : kbbug


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