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

			

'Use only one of the macros named {Private Sub UserForm_Initialize() } 'Top Left Option Explicit Private Sub UserForm_Initialize() Me.StartUpPosition = 0 Me.Top = 0 Me.Left = 0 End Sub 'Top Right Option Explicit Private Sub UserForm_Initialize() Me.StartUpPosition = 0 Me.Top = 0 Me.Left = Application.Left + Application.Width - Me.Width End Sub 'Lower Left Option Explicit Private Sub UserForm_Initialize() Me.StartUpPosition = 0 Me.Top = Application.Top + Application.Height - Me.Height Me.Left = 0 End Sub 'Lower Right 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 'Place This Code in a Standard Module Option Explicit Sub CallUserForm() UserForm1.Show End Sub

How to use:

  1. Open the application to be used (Excel, Word etc.).
  2. Alt + F11 to open the VBE.
  3. Insert | UserForm.
  4. Select one of the macros (named Private Sub UserForm_Initialize() ) from above and paste it in the Code Section for the User Form.
  5. Insert | Module.
  6. Paste the code from above designated for the Standard Module.
  7. Close the VBE (Alt + Q or press the X in the top right corner).
 

Test the code:

  1. Tools | Macro | Macros...
  2. Select Macro1 and press Run.
 

Sample File:

User Form Position.zip 16.56KB 

Approved by mdmackillop


This entry has been viewed 179 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express