Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Keydown and SelStart problem

If you create a Textbox TextBox1 and give it text of "abcdefg" in the
properties window then why doesn't the second event procedure below
select "de" when you press the right arrow on the keyboard when the
textbos has got the focus ??!

Any help greatly appreciated
Jason.


Private Sub TextBox1_GotFocus()
TextBox1.SelStart = 0
End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
Select Case KeyCode
Case vbKeyRight
With TextBox1
.SelStart = 3
.SelLength = 2
End With
Case Else
End Select
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Keydown and SelStart problem

You're letting the right arrow through. You have to kill it:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Select Case KeyCode
Case vbKeyRight
With TextBox1
.SelStart = 3
.SelLength = 2
End With
KeyCode = 0 ''<<<<<
End Select
End Sub


--
Jim
"jase" wrote in message
ups.com...
| If you create a Textbox TextBox1 and give it text of "abcdefg" in the
| properties window then why doesn't the second event procedure below
| select "de" when you press the right arrow on the keyboard when the
| textbos has got the focus ??!
|
| Any help greatly appreciated
| Jason.
|
|
| Private Sub TextBox1_GotFocus()
| TextBox1.SelStart = 0
| End Sub
|
| Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
| ByVal Shift As Integer)
| Select Case KeyCode
| Case vbKeyRight
| With TextBox1
| .SelStart = 3
| .SelLength = 2
| End With
| Case Else
| End Select
| End Sub
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Keydown and SelStart problem

Cheers Jim
Works beautifully.
Have you got any examploes to help me understand how this has worked?

Jason

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem SelStart and SelLength RB Smissaert Excel Programming 1 November 3rd 05 11:11 AM
keydown event Peter T Excel Programming 0 April 18th 05 02:03 PM
keydown event K Dales[_2_] Excel Programming 0 April 18th 05 12:46 PM
Form Focus and SelStart Geoff[_9_] Excel Programming 0 April 4th 05 07:20 PM
keydown event jim c. Excel Programming 1 October 10th 03 03:16 AM


All times are GMT +1. The time now is 05:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"