Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Force Scroll Bar Down on TextBox Control
I have a text box which I am appending text to via code. I want the ability
to force the scroll bar down to the bottom each time the text is appended. I put the following code into the AfterUpdate Event. However this event does not fire when adding text via code. The only way I can get it to work is if I change the Userform .Enabled property to FALSE. However this disables the buttons on the userform. So then I tried to simply set the Enabled property of the Textbox to FALSE. Howevever when I do this, the textbox does not scroll nor are the scroll bars visible. How do I allow the user to scroll, force the scroll bar to the bottom and not disable any button on the form? Private Sub TextBox1_AfterUpdate() On Error Resume Next lLine = TextBox1.CurLine TextBox1.CurLine = lLine On Error GoTo 0 End Sub Thanks EM |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Force Scroll Bar Down on TextBox Control
Untested but can't you simply place the code to move the scroll bar
immediately after the code you are using to append and not rely on an event to run the code. -- Regards, OssieMac "Excel Monkey" wrote: I have a text box which I am appending text to via code. I want the ability to force the scroll bar down to the bottom each time the text is appended. I put the following code into the AfterUpdate Event. However this event does not fire when adding text via code. The only way I can get it to work is if I change the Userform .Enabled property to FALSE. However this disables the buttons on the userform. So then I tried to simply set the Enabled property of the Textbox to FALSE. Howevever when I do this, the textbox does not scroll nor are the scroll bars visible. How do I allow the user to scroll, force the scroll bar to the bottom and not disable any button on the form? Private Sub TextBox1_AfterUpdate() On Error Resume Next lLine = TextBox1.CurLine TextBox1.CurLine = lLine On Error GoTo 0 End Sub Thanks EM |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Force Scroll Bar Down on TextBox Control
The following sub does not make sense to me. lLine is saved to the current
CurLine value and then you are setting Curline to the same value so the cursor should not move. CurLine is the current line where the cursor is positioned. Private Sub SetScrollBar() UserForm1.TextBox1.SetFocus lLine = UserForm1.TextBox1.CurLine 'Public Variable UserForm1.TextBox1.CurLine = lLine UserForm1.TextBox1.SetFocus End Sub You need to save CurLine to lLine variable immediately after entering the last of the data in the TextBox1 while the cursor is still on the last line. I have not been able to do that reliably because the user might move up through the textbox to edit an error and then move to another control from there. From my testing it appears that you can only set the cursor to the specified CurLine if the TextBox has focus. Therefore must SetFocus to the TextBox first. Having said that, it also appears that it only works if done in the last line of code executed before the End Sub like the following example. Any code after the line of code to set the cursor to Curline will nullify the CurLine setting:- Sub test() UserForm1.Show vbModeless UserForm1.TextBox1.SetFocus UserForm1.TextBox1.CurLine = 6 'Can use a variable in lieu of 6 End Sub Next I found that using the above code to set the cursor to the last line then it would only work if I used a value 1 less then should be required. Example if 8 lines then should be 7 because of Zero to 7 line count. However, I had to set it to 6 or I got an error. Also 6 actually set it to the last line which should be 7. Now if I run code from a Command button after the form is opened then I had to set it 7 to get the last line like the following:- Private Sub CommandButton1_Click() Me.TextBox1.SetFocus Me.TextBox1.CurLine = 7 End Sub The 6 or 7 just does not make sense to me. My next test was to use SendKeys to send a Ctrl/End when the control gets focus. As much as I dislike the use of SendKeys it appears to be more reliable and I dont think that sending Ctrl/End after the TextBox has focus will ever cause a problem. (Note: Must still SetFocus to the TextBox first.) Sub test() UserForm1.Show vbModeless UserForm1.TextBox1.SetFocus Application.SendKeys ("^{END}") End Sub The above code also worked well from a CommandButton as per the following:- Private Sub CommandButton1_Click() Me.TextBox1.SetFocus Application.SendKeys ("^{END}") End Sub Just a little added extra. I also tried to use both the CurLine method and Sendkeys method with the TextBox Enter Event. It does not work when you use the mouse to click on the TextBox. In Help it says that Enter Event code actually takes place before the real enter takes place and I am sure that this is the reason for this. It does not actually have focus until the Enter Event code is finished running. Hope this all helps. It was an interesting experiment for myself but in the end I didnt progress all that far. -- Regards, OssieMac |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Force to update textbox value to cell | Excel Programming | |||
How to force smooth scroll in excel? | Excel Discussion (Misc queries) | |||
How to force selection of all current text in textbox control onentry? | Excel Programming | |||
How to move cursor from one textbox control to another textbox con | Excel Programming | |||
How to move cursor from one textbox control to another textbox con | Excel Programming |