Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
SetFocus in user form
I am creating a user form with a text box that starts with the number
0. I've got the userform_activate to set textbox1.setfocus so that the cursor is in the text box. However, I find that the cursor is blinking at the end of the 0, so that the user has to tap to the front and then go forward to highlight the 0 in order to put in a new number. How can I set it so that the 0 is highlighted right away, and the user can input the right number over the 0 immediately? Many thanks for advice! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
SetFocus in user form
Try this one John
Private Sub UserForm_Activate() With Me.TextBox1 .SelStart = 0 .SelLength = Len(.Text) .SetFocus End With End Sub -- Regards Ron de Bruin (Win XP Pro SP-1 XL2000-2003) www.rondebruin.nl "John Tjia" wrote in message om... I am creating a user form with a text box that starts with the number 0. I've got the userform_activate to set textbox1.setfocus so that the cursor is in the text box. However, I find that the cursor is blinking at the end of the 0, so that the user has to tap to the front and then go forward to highlight the 0 in order to put in a new number. How can I set it so that the 0 is highlighted right away, and the user can input the right number over the 0 immediately? Many thanks for advice! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
SetFocus in user form
Private Sub TextBox1_Enter()
With TextBox1 .SelStart = 0 .SelLength = Len(.Text) End With End Sub -- HTH. Best wishes Harald Followup to newsgroup only please. "John Tjia" wrote in message om... I am creating a user form with a text box that starts with the number 0. I've got the userform_activate to set textbox1.setfocus so that the cursor is in the text box. However, I find that the cursor is blinking at the end of the 0, so that the user has to tap to the front and then go forward to highlight the 0 in order to put in a new number. How can I set it so that the 0 is highlighted right away, and the user can input the right number over the 0 immediately? Many thanks for advice! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
SetFocus in user form
John,
I'm not sure about the highlighting aspect of your question, but here's what you can do to shift the insertion point to the left of the zero: With UserForm1.TextBox1 .Text = "0" .SetFocus .SendKeys{LEFT} End With -- Dennis Eisen |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
SetFocus in user form
Thanks to all! The .SelStart = 0, .SelLength = Len(.Text) code is
great. Dennis, I tried your code, but VBA didn't accept the .SendKeys{LEFT}. I saw something once that was the equivalent of a Tab command in the userform, i.e., set the focus on the next item in the tab order, and then do a Shift+Tab equivalent to back up. Thanks for the reply. (DennisE) wrote in message ... John, I'm not sure about the highlighting aspect of your question, but here's what you can do to shift the insertion point to the left of the zero: With UserForm1.TextBox1 .Text = "0" .SetFocus .SendKeys{LEFT} End With -- Dennis Eisen |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
SetFocus in user form
John,
I was (incorrectly) trying to recall from memory the form of the SendKeys that would do the shifting. The correct form of the instruction is as follows, and will result in "AB|C" showing up in the TextBox, rather than "ABC|". Sub ShiftLeft( ) UserForm1.TextBox1.Text = "ABC" Application.SendKeys ("{LEFT}") UserForm1.Show End Sub And to be precise about the .SelLength and .SelStart properties, you'd want to use .SelStart = Len(.Text) - 1 and ..SelLength = 1 to get you to shift the insertion point one character to the left and highlight the rightmost character. -- Dennis Eisen |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
SetFocus in user form
Dennis later said in a separate thread:
I've been wrestling with this one for days, and I just can't seem to pull it off. What I'd like to do when a certain TextBox on a UserForm takes the focus is to have the insertion point automatically move one space to the left. So, for example, if the TextBox contains ""ABC" upon taking the focus what I want to see is "AB|C"; I've been trying to do this by using Application.SendKeys "{LEFT}" in some manner but to no avail. I can obviously do it manually by pressing the left arrow key, but I want to do it in VBA so as to remind the user of how the data entry appearing in that particular TextBox is to be modified. Anyone have any ideas on how to do this? -- Dennis Eisen so even he doesn't appear to be still enamored with his suggeste solution. -- Regards, Tom Ogilvy "John Tjia" wrote in message m... Thanks to all! The .SelStart = 0, .SelLength = Len(.Text) code is great. Dennis, I tried your code, but VBA didn't accept the .SendKeys{LEFT}. I saw something once that was the equivalent of a Tab command in the userform, i.e., set the focus on the next item in the tab order, and then do a Shift+Tab equivalent to back up. Thanks for the reply. (DennisE) wrote in message ... John, I'm not sure about the highlighting aspect of your question, but here's what you can do to shift the insertion point to the left of the zero: With UserForm1.TextBox1 .Text = "0" .SetFocus .SendKeys{LEFT} End With -- Dennis Eisen |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
user form | Excel Discussion (Misc queries) | |||
user form | Excel Discussion (Misc queries) | |||
How do I fill a cell in a user form from a selection on same form? | Excel Discussion (Misc queries) | |||
User form | New Users to Excel | |||
I am looking to see if anybody has an equivalant user form to Outlooks CONTACT form | Excel Programming |