Search code examples
excelvba

Excel VBA Userform: Scroll Bar location on Userform Load


Ok I have been scratching my head as to why this userform's scroll bar keeps starting at this location for some reason:

enter image description here

Here's the property menu for this userform and i'm not sure what I did wrong. I also am making sure that the userform's Developer mode state has the scroll bar fully scrolled up.

Any thoughts?

enter image description here


Solution

  • I can only guess (because the truth is hidden behind the blue box in your image), but it is likely that, when you show the form, a control gets the focus that is (fully) visible only when the form content is scrolled.

    By default, focus is set to the control with TabIndex = 0. Alternative could be that you use SetFocus for example in the Activate-Trigger of the form.

    Small test form with 2 Textboxes:
    When focus is on the top textbox: Scrollbar is at the top.

    focus is on the top textbox

    Now setting TabIndex = 0 for the 2nd textbox (that is not completely visible)

    TabIndex=0 for the 2nd textbox

    Will show the form scrolled down

    show the form scrolled down