I searched for this online for a while, and I did find a few solutions, but none of them appear to help me.
I have a Userform in Excel 2010, which I would like to center on the Excel window. I have dual monitors, and it always seems to center itself between the two monitors. I know there are properties you can edit, such as StartUpPosition and such, to control where it goes, but it seems changing these parameters does nothing. This is the code I found online, which many users attested to working for them. My form is named "HighlightForm"
Private Sub HighlightForm_Activate()
With HighlightForm
.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
End Sub
This, however, does not change where my form is placed at all. It remains in the center. I even tried changing all these parameters to zero, to no avail. I'm placing this code in the UserForm code itself, which I understand to be the correct placement. I've also tried HighlightForm_Initialize(), and it still won't respond to any changes.
Is there something blatantly obvious I'm missing? I don't imagine this to be a very difficult question, but I'm really stumped. Thanks in advance for any help.
I found this code working perfectly for me
Private Sub UserForm_Activate()
'Position top/left of Excel App
Me.Top = Application.Top
Me.Left = Application.Left
'Approx over top/left cell (depends on toolbars visible)
Me.Top = Application.Top + (Application.UsableHeight / 2)
Me.Left = Application.Left + (Application.UsableWidth / 2)
End Sub
To note that you can adjust the "/2" to center a bit more as it might give a different feeling with smaller monitors (it adjust the top left of the Userform to the center of your screen). My Code has 2.3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With