|
|
|
|
|
|
Multiple Apps
|
Set User Form Position to (Top Left, Top Right, Lower Left, or Lower Right) of the Application
|
|
Ease of Use
|
Easy
|
Version tested with
|
2002, 2003
|
Submitted by:
|
Jacob Hilderbrand
|
Description:
|
This macro demonstrates how to position a User Form to one of the four corners of the application.
|
Discussion:
|
By default a User Form will be positioned at the center of the application, however, sometimes you may want to position it elsewhere. The macro shows how to change the position when you do not know what the Top and Left values will be.
|
Code:
|
instructions for use
|
Option Explicit
Private Sub UserForm_Initialize()
Me.StartUpPosition = 0
Me.Top = 0
Me.Left = 0
End Sub
Option Explicit
Private Sub UserForm_Initialize()
Me.StartUpPosition = 0
Me.Top = 0
Me.Left = Application.Left + Application.Width - Me.Width
End Sub
Option Explicit
Private Sub UserForm_Initialize()
Me.StartUpPosition = 0
Me.Top = Application.Top + Application.Height - Me.Height
Me.Left = 0
End Sub
Option Explicit
Private Sub UserForm_Initialize()
Me.StartUpPosition = 0
Me.Top = Application.Top + Application.Height - Me.Height
Me.Left = Application.Left + Application.Width - Me.Width
End Sub
Option Explicit
Sub CallUserForm()
UserForm1.Show
End Sub
|
How to use:
|
- Open the application to be used (Excel, Word etc.).
- Alt + F11 to open the VBE.
- Insert | UserForm.
- Select one of the macros (named Private Sub UserForm_Initialize() ) from above and paste it in the Code Section for the User Form.
- Insert | Module.
- Paste the code from above designated for the Standard Module.
- Close the VBE (Alt + Q or press the X in the top right corner).
|
Test the code:
|
- Tools | Macro | Macros...
- Select Macro1 and press Run.
|
Sample File:
|
User Form Position.zip 16.56KB
|
Approved by mdmackillop
|
This entry has been viewed 179 times.
|
|