Home |
Search |
Today's Posts |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
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 |