[RESOLVED] display Userform on second monitor
I'm sure this has been asked before, but I can't seem to find any posts that address it. A user has a dual monitor system and always opens Excel files on his SECONDARY monitor. When the Excel sheet has macros that display a modeless userform, the form always appear on the PRIMARY monitor, not the monitor displaying the Excel worksheet.
How does one ensure the userform appears on the same monitor as the Excel worksheet?
Through my searches I've seen several references to setting userform.StartUpPosition = 0 and adjusting userform.Left and userform.Top based the values of Application.Width and Application.Height, but that doesn't change the behavior at all in the above scenario.
Re: display Userform on second monitor
Code:
Private Sub UserForm_Activate()
Me.Left = Application.Left + 100
End Sub
seems to do the job, of you want it centered in the exel window you can try like
Code:
Private Sub UserForm_Activate()
Me.Left = Application.Left + (Application.Width - Me.Width) / 2
End Sub
similar for top
Re: display Userform on second monitor
Hmm, no difference. Sheet is on the secondary monitor but userform is still on the primary monitor. I was using:
Code:
Me.Left=(Application.Width - Me.Width) / 2
Re: display Userform on second monitor
Ah, I found the problem. I had another routine that was "validating" the value of userform.Left and userform.Top and was setting negative values to zero. When I removed the validation, everything worked fine. I didn't realize that Application.Left could have negative values in a dual monitor situation.