+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    06-09-2009
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    89

    Scroll Bars in a form

    What I need to do is add a scroll bar to my text box in my form. I used the properties of the text box to add a scroll bar but when you preview it you can't see it. When you click somewhere inside the form it appears and is workable but not when it hasn't been clicked on. How do I make the scroll bar appear from the start. this is a vertical one ad is on a text box within the form
    Last edited by dextras; 07-04-2009 at 07:12 AM.

  2. #2
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,443

    Re: Scroll Bars in a form

    The TextBox MultiLine Property needs setting to True. The scrokkbar will become visible as data is entered
    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 consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

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


    Code Tags: Make your code easier for us to read

  3. #3
    Registered User
    Join Date
    06-09-2009
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Scroll Bars in a form

    Already done. The textbox already has data in it. I am not using it as a thing to be able to have data entered into it. I guess I should be using something else. Label? If so how would then deal with the scroll vars

  4. #4
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,443

    Re: Scroll Bars in a form

    What data are you putting in? maybe you could use a listbox
    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 consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

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


    Code Tags: Make your code easier for us to read

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: Scroll Bars in a form

    This works for me.
    Userform textbox and command button

    Code:
    Private Sub UserForm_Activate()
    
        Dim objTemp As Object
        
        Set objTemp = Me.ActiveControl
        TextBox1.SetFocus
        objTemp.SetFocus
        
    End Sub
    
    Private Sub UserForm_Initialize()
    
        With TextBox1
            .ScrollBars = fmScrollBarsVertical
            .MultiLine = True
            .WordWrap = True
            .Text = "Here is some text Here is some text Here is some text Here is some text Here is some text Here is some text"
        End With
        
    End Sub
    If the textbox is first in the Tab order the activation event code in not required.

    The scrollbars are only displayed if the text is long enough.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Registered User
    Join Date
    06-09-2009
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Scroll Bars in a form

    Here's my spreadsheet. How would I add in the code? I'm not sure where you'd add it. It's for the "help" userform.
    Attached Files Attached Files

  7. #7
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,443

    Re: Scroll Bars in a form

    Just add this to your userform
    Code:
    Private Sub UserForm_Initialize()
     Me.TextBox2.SetFocus
    End Sub
    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 consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

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


    Code Tags: Make your code easier for us to read

  8. #8
    Registered User
    Join Date
    06-09-2009
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Scroll Bars in a form

    That works except it focuses to the bottom of the scroll box. This means that then you are scolled to the bottom when you open it. How can i fix this?

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: Scroll Bars in a form

    All you actually need in your userform, to fix the problem, is the following.

    Code:
    Private Sub UserForm_Initialize()
    
        With TextBox2
            .TabIndex = 0
            .ScrollBars = fmScrollBarsVertical
            .SelStart = 0
        End With
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  10. #10
    Registered User
    Join Date
    06-09-2009
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Scroll Bars in a form

    Thank you, that's exactly what i needed. I would have thought that you wouldn't need to do all that other stuff to get it done
    +1

  11. #11
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,443

    Re: Scroll Bars in a form

    Your post does not comply with Rule 9 of our Forum RULES. If you solve a problem yourself before anyone else has responded, please take a moment to describe your solution, chances are some other member will benefit. And please never edit a thread in which someone else has responded.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    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 consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

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


    Code Tags: Make your code easier for us to read

  12. #12
    Registered User
    Join Date
    06-09-2009
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Scroll Bars in a form

    ^ I didn't solve it myself. You gave me stuff which woked but not completely but then Andy Pope gave me this:
    Quote Originally Posted by Andy Pope View Post
    All you actually need in your userform, to fix the problem, is the following.

    Code:
    Private Sub UserForm_Initialize()
    
        With TextBox2
            .TabIndex = 0
            .ScrollBars = fmScrollBarsVertical
            .SelStart = 0
        End With
        
    End Sub
    which is above

    EDIT: I already put it as solved. I'm confused lol

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