VBA - User Forms and Multiple Screens

vba_monkey

Board Regular
Joined
Dec 18, 2013
Messages
112
Hello,

Only a minor issue this one but it's slightly annoying so I wanted to see if there was a fix.

When running a macro that has a user form on a machine with more than one screen, the userform always appears on the opposite screen to the active workbook. Is it possible to specify which screen you want the form to appear on (as in, on top of the active workbook)?

Thanks
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hello,

Only a minor issue this one but it's slightly annoying so I wanted to see if there was a fix.

When running a macro that has a user form on a machine with more than one screen, the userform always appears on the opposite screen to the active workbook. Is it possible to specify which screen you want the form to appear on (as in, on top of the active workbook)?

Thanks

I use this in the Userform_Initialize sub

Code:
Me.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
Me.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)

It should always center the userform over excel.
 
Upvote 0
First attemp didnt work but I've managed to get it to work by changing it to this:

Code:
UserForm1.Left = Application.Left + (0.5 * Application.Width) - (0.5 * Application.Width)
UserForm1.Top = Application.Top + (0.5 * Application.Height) - (0.5 * Application.Height)

The form is on the right screen but is on the far left, how would I move it to the middle?
 
Last edited:
Upvote 0
Oh sorry. I didn't copy and paste the code, so that is my typing error. Try this.

Code:
With Me
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
End With
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,973
Members
448,933
Latest member
Bluedbw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top