userform screen placement

dinotom

Active Member
Joined
Aug 2, 2009
Messages
357
Is there any way to tell a userform to always open in the center of the excel screen? It always seems to open somewhere in outer space on multiple screen setups.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
This is great guys, and I've been using it consistently since I found it, the only problem is that it only works if there's only ONE excel sheet open per monitor. I'm working with two excel instances in the same window, and even with directly activating the workbook I want it to reference before running this code, the userform will still open centered in my other excel instance and I can't figure out how to reference ThisWorkbook with Application.Left/Right etc to get it to center in the workbook that the userform is issued from. The problem being that I have a userform that opens another userform. The first opens centered over ThisWorkbook, the second will open centered on the other workbook opened in the same monitor space. How do I get it to only open centered in the middle of the one instance I need to pinpoint?
 
Upvote 0
The following code will center the userform in Excel's window:

Code:
With UserForm1
  .StartUpPosition = 0
  .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
  .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
  .Show
End With</pre>
Thank you! I'm using a three-monitor set-up, and this instantly fixed the problem for me.
 
Upvote 0
The posted solution works unless you have a code window open on another monitor. If you do it will open in that window. At least that's what happened for me.
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,172
Members
449,071
Latest member
cdnMech

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