Can't Change Size or Position of Object in Custom Dialog (117134)



The information in this article applies to:

  • Microsoft Excel for Windows 95 7.0a
  • Microsoft Excel for Windows 5.0c
  • Microsoft Excel for the Macintosh 5.0a

This article was previously published under Q117134

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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. 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


Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbcode kbprb kbProgramming KB117134