XL: Can't Change Size or Position of Object in Custom Dialog

ID: Q117134

The information in this article applies to:

SYMPTOMS

In Microsoft Excel, you cannot use the Width, Height, Top, or Left properties of the DrawingObjects object to change the size or position of an object in a custom dialog box while the dialog box is displayed.

NOTE: This limitation does not apply to objects in UserForms in Microsoft Excel 97 for Windows or Microsoft Excel 98 Macintosh Edition.

CAUSE

This is by design in Microsoft Excel. You can move and size an object on a dialog sheet, and the object is displayed with this size and position when you display the dialog box. However, because a dialog box is not updated during an event macro (only after the event macro finishes), you cannot dynamically move or resize an object in the dialog box while the dialog box is displayed.

Note that you also cannot change the size or position of a custom dialog box when you use the Show method to display the dialog box.

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 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/

To work around this behavior, you can link a picture of an object on a worksheet to a custom dialog box, and then move the object on the worksheet using a Visual Basic module assigned to a button in the dialog box.

Example of Visual Basic Procedure

For an example of using this method, do the following:

1. On a new worksheet (Sheet1), insert a picture in the range A1:C6.

2. On the Tools menu, click Options. Select the View tab, and under

   Window Options, clear the Gridlines check box. Click OK. Select the
   Picture, and click Copy on the Edit menu.

3. On the Insert menu, point to Macro, and then click Dialog. On the
   Edit menu, click Paste. Drag the picture to the dialog box. Click
   the Formula bar, and enter the following formula:

      =Sheet1!$A$1:$C$6

4. Size the picture on the dialog box as desired. The picture on the
   dialog box is now linked to the picture on the worksheet (Picture 1).

5. On the Forms toolbar, click the Create Button button. Drag on the
   dialog box to create a button (Button 5). Select the button, and click
   the Edit Code button on the Forms toolbar. In the new module, enter the
   following code:

      ' Code assigned to Button 5.
      Sub Button5_Click()
          ' Change width and height of picture.
          With Worksheets("Sheet1").DrawingObjects("Picture 1")
              .Width = 30
              .Height = 40
         End With
      End Sub

      ' Macro to display dialog box.
      Sub Display_Dialog()
          DialogSheets("Dialog1").Show
      End Sub

6. On the Tools menu, click Macro. In the Macro Name/Reference list, select
   Display_Dialog, and click Run.

Note that you can also use the Top and Left properties of the DrawingObects object to change the location of the object on the dialog box.

MORE INFORMATION

For more information about positioning a custom dialog box, query on the following words in the Microsoft Knowledge Base:

   directly and possible and on-screen and position and dialog

Additional query words: 5.00 5.00a 5.00c 7.00 7.00a XL5 XL7 vba
Keywords          : kbcode kbprg PgmOthr PgmHowto 
Version           : WINDOWS:5.0,5.0c,7.0,7.0a; MACINTOSH:5.0
Platform          : MACINTOSH WINDOWS
Issue type        : kbprb

Last Reviewed: May 17, 1999