+ Reply to Thread
Results 1 to 9 of 9

Thread: UserForm Not Opening

  1. #1
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    UserForm Not Opening

    Hi all,

    So I have a userform that opens and then closes upon the workbook opening. The reason that it does this is to get relative coordinates for that userform to appear, before the user has scrolled on the page.

    Anyways, when I press the button to open the userform again, it doesn't open, and the entire excel screen loses focus (the bar up top is the shaded gray blue). No matter how many times I press it, it won't start. However if I go into the VB Editor, hit the stop button, and then go back and press the button for that userform, it will appear, but it will not appear in the proper area on the screen. I'm not sure much worried about it appearing on the proper area on the screen as I am to just getting the userform to appear again.

    Anyone have any ideas as to what might be happening? I forgot to mention that the Forms open up properly on my computer, however they do not open up and I get this issue I described when I work on another computer of a different screen resolution. As you can see, the zoom is adjusted in the workbook open according to the screen resolution, this way the user is looking at the same view of the workbook everytime they open it.

    Here is my workbook open code

    Private Declare Function GetSystemMetrics32 Lib "User32" _
        Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
    
    
    Public Sub Workbook_open()
    Application.WindowState = xlMaximized
    
    Dim w As Long, h As Long
        w = GetSystemMetrics32(0) ' width in points
        h = GetSystemMetrics32(1) ' height in points
    
    
    Application.ScreenUpdating = False
    ActiveWindow.Zoom = (w * 130) / 1600
    Application.ScreenUpdating = True
    
    Range("I8").Select
    initialForm = True
    
    ShowForm
    Unload PMD_Wizard 'unloads the ShowForm call
    ActivitiesMacro
    Unload Activities 'Unloads the activities call
    
    End Sub
    Here is my code for calling the ShowForm (The same thing happens with the activities macro)

    Public Sub ShowForm()
    If firstElementPosit Then
    Dim PS As Positions
    PS = PositionForm(PMD_Wizard, Range("Z17"), -20, -3, cstFhpFormLeftCellRight, cstFvpFormTopCellTop)
    firstElementPosit = False
    formLeft = PS.FrmLeft
    formTop = PS.FrmTop
    End If
    PMD_Wizard.top = formTop
    PMD_Wizard.Left = formLeft
    PMD_Wizard.Show vbModeless
    
    End Sub
    
    Public Sub ActivitiesMacro()
    If firtActivPosit Then
    Dim PS As Positions
    PS = PositionForm(Activities, Range("Y17"), 8, -3, cstFhpFormLeftCellRight, cstFvpFormTopCellTop)
    activLeft = PS.FrmLeft
    activTop = PS.FrmTop
    firtActivPosit = False
    End If
    Activities.top = activTop
    Activities.Left = activLeft
    Activities.Show vbModeless
    
    End Sub
    Last edited by andrew c.; 07-06-2011 at 07:25 PM.

  2. #2
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: UserForm Not Opening

    Anyone have any ideas?

  3. #3
    Registered User
    Join Date
    06-29-2011
    Location
    California
    MS-Off Ver
    Excel 2003/2007
    Posts
    58

    Re: UserForm Not Opening

    Your if statements look a bit off -

    I'd simply test them by putting
    msgbox "I'm actually passing into the if statement"
    in order to make sure it is actually appearing.

    Cause it looks like you're just saying..

    If 0 Then
    
    End If

  4. #4
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: UserForm Not Opening

    I don't think all the code is there so it's hard to see where the error is. Try attaching an example workbook.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  5. #5
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: UserForm Not Opening

    Ok sorry that the code was a bit hard to jump into.

    I stripped all information out of the file and kept only what was necessary to reproduce the error. It works when my resolution is set to 1600x900 pixels (on workbook open, it shouldn't have to adjust the zoom at all because of this the resolution with the proper zoom the adjustment ratio was created at.

    When the workbook opens, it opens and closes the 2 forms, so as to get the proper positioning of the forms before the user scrolls on the page (which would mess up the positioning if you try to calcualate it again). The positioning is stored into global variables and then called upon again when trying to open up the form.

    You can see that when you click the buttons to open up the form that the screen loses focus and the forms do not appear. I noticed that if you go into the VBE editor, and hit the stop button, and then you hit the form button, the form will appear in the upper left, but it will not appear in the proper location(about midway down the screen on the far right).

    Any help or suggestions would be great!

    Thanks!
    Attached Files Attached Files

  6. #6
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: UserForm Not Opening

    As you showed perfectly well yourself you don't need to open a userform to set the screencoordinates:
    You can store those coordinates everywhere in the workbook or in a public variable.
    But you can also make this code part of the userform module:

    Private Declare Function GetSystemMetrics32 Lib "User32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
    
    Private Sub Userform_Initialize()
      tag=GetSystemMetrics32(0)& "|" & GetSystemMetrics32(1)
    End Sub
    I don't see any benefit in using several userforms in 1 project.
    The module 'modformpositioner' seems to me to be totally redundant.



  7. #7
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: UserForm Not Opening

    snb, I'm not quite following what you are saying.

    what exactly is this?

    Private Sub Userform_Initialize()
      tag=GetSystemMetrics32(0)& "|" & GetSystemMetrics32(1)
    End Sub
    and does this have anything to do with why the userforms aren't popping up? Are the userforms not popping up when you test it out?

    For proper UI, there needs to be multiple userforms. There's A LOT more to this worksheet than is visible to you guys, but I had to remove everything for confidentiality.

    Thanks for your help guys!

  8. #8
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: UserForm Not Opening

    I've figured out that setting the positioning is somehow causing this.

    Activities.top = activTop
    Activities.Left = activLeft
    when I comment out these lines of code, they form opens, however it just opens in the upper left hand corner and not where I want it (hence why I have set these coordinates to position it.) Any ideas as to why this codes would make it so the form isn't appearing? Is it possible that the form is appearing, but somewhere that is off the screen and not visible?

    Apparently activTop = 226 on my computer and activLeft = 906, no matter what the resolution is. If I change the resolution, is it possible like I suggested above that it is placing the form off the screen? If so how would I know?
    Last edited by andrew c.; 07-01-2011 at 11:39 AM.

  9. #9
    Registered User
    Join Date
    06-07-2011
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: UserForm Not Opening

    So I figured out that it was displaying the form off the screen because of the positioning. My main issue now is figuring out a way to scale the positioning so it works with any screen resolution. (Like the way I had it adjust the zoom for any screen resolution, however this seems to be a bit trickier and I can't get constant results)

    Any ideas of what to use to set up a scaling ratio?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0