Use command buttons to advance vertical userform textbox scrollbar up or down

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
884
Office Version
  1. 365
Platform
  1. Windows
Title describes solution. Image below shows scrollbar and bottom pointer with clumsy red circle.
What I'd like is simple: button click code that would operate the scrollbar down click button as if done manually.

For this application' textboxes with large amounts of text, button clicks work much more efficiently for me.
I've tried the following code and other suggestions. Nothing works.
Code:
Private Sub cmdNXT_Click()
  'Activate the textbox
VERSELINK.TextBox1.SetFocus
    'Send the down arrow key to the textbox
    SendKeys "{DOWN}"
End Sub
When the button this code is clicked, nothing happens. Also using Sendkeys seems like an awfully crude way to do this.
I can't figure out the correct code at this point.

This code works great - but for moving through listbox Sheet cell values. I don't want to scroll through a Listbox. Button code must advance the textbox text down or up
-of specific cell text - not from cell to cell as this code shows.
Code:
Private Sub cmdNXTVERSE_Click()
Dim count As Integer, n As Variant
n = ListBox3.ListIndex
    n = Me.ListBox3.ListCount - 1
    Select Case Me.ListBox3.ListIndex
    Case Is < n
        Me.ListBox3.ListIndex = Me.ListBox3.ListIndex + 1
    Case Else
        Me.ListBox3.ListIndex = 0
    End Select
End Sub

Sorry if too wordy. Just giving as thorough a description of the problem.
Any help greatly appreciated.
Thanks,
cr
 

Attachments

  • USE BUTTON TO CLICK SCROLLBAR BOTTOM DOWN ARROW.png
    USE BUTTON TO CLICK SCROLLBAR BOTTOM DOWN ARROW.png
    77.8 KB · Views: 9

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Tested with a 4 line textbox - seems to work. Use your own textbox and button names. It worked for me with or without DoEvents. You might need it.
If you are at the last line, the following will take you back to the top.
VBA Code:
Private Sub CommandButton1_Click()

With Me.TextBox1
    .SetFocus
    'DoEvents
    If .CurLine = .LineCount - 1 Then
        .CurLine = 0
        .SelStart = 0
        .SelLength = 0
        Exit Sub
    End If
    .CurLine = .CurLine + 1
End With
'if userform controls stop responding, enable next line
'Me.CommandButton1.SetFocus

End Sub
 
Upvote 0
Tested with a 4 line textbox - seems to work. Use your own textbox and button names. It worked for me with or without DoEvents. You might need it.
If you are at the last line, the following will take you back to the top.
VBA Code:
Private Sub CommandButton1_Click()

With Me.TextBox1
    .SetFocus
    'DoEvents
    If .CurLine = .LineCount - 1 Then
        .CurLine = 0
        .SelStart = 0
        .SelLength = 0
        Exit Sub
    End If
    .CurLine = .CurLine + 1
End With
'if userform controls stop responding, enable next line
'Me.CommandButton1.SetFocus

End Sub
Hi Micron - thanks for helping. I hanged the +1 to the number of visible text lines in the userform textbox height - in this case 14. This code does work and moves the cursor to the bottom line of the last visible text.

This apps textboxes have text which extends way below the textbox's height - which is how a vertical scrollbar enables continuous scrolling past the
visible text as far down all the way to the end of the text.


To work correctly, the code above would reset its position at every click and move down 14 more lines to work right to display a new set of 14 text lines in the textbox and keeps doing that until enough button clicks reaches the end of the text.

The way the code is now, the button click stops advancing down the text after just the first click. I'm not as knowledgeable about using a For loop but maybe that might be a fix - or something simple like resetting the button action to advance 14 more lines, as mentioned above. Again not to overkill this - just some thoughts.

Thanks again for all your help in this.
cr
 
Upvote 0
Not clear if you have a solution or not. Seems like not. Your op didn't say you wanted to move 14 lines at a time, so it's never really "simple' is it? No idea why it would stop after one click seeing as how you didn't post your latest code version. In retrospect, to me this seems like a bit of a Rube Goldberg machine. You have a control that advances by one line if you click the button, and a whole 'page' of lines if you click the space below the slider. Why reinvent the wheel to get the same behaviour?
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,953
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top