|
-
Apr 25th, 2016, 05:04 PM
#1
Thread Starter
Fanatic Member
[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.
-
Apr 26th, 2016, 04:14 AM
#2
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Apr 26th, 2016, 12:02 PM
#3
Thread Starter
Fanatic Member
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
-
Apr 26th, 2016, 01:07 PM
#4
Thread Starter
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|