Results 1 to 4 of 4

Thread: [RESOLVED] display Userform on second monitor

  1. #1

    Thread Starter
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Resolved [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.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  3. #3

    Thread Starter
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    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

  4. #4

    Thread Starter
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    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
  •  



Click Here to Expand Forum to Full Width