Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm using a form with VBA and the form has several text boxes. When entering
information I need to be able to put carriage return/line feeds into the text. However just hitting the Enter key causes the next field in the form to become active (leaving the field that I was editing) - like TAB does. If I want carriage return/line feed I have to type CTRL-Enter. Is there a way to cause carriage return/line feeds to be put into a form text box using just the Enter key? This may seem like a small thing but others use this form too and hitting just Enter (for CR/LF) is a hard habit to break. Thanks, Will |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
In the textbox properties is EnterKeyBehavior.
Set this to True. RBS "roadkill" wrote in message ... I'm using a form with VBA and the form has several text boxes. When entering information I need to be able to put carriage return/line feeds into the text. However just hitting the Enter key causes the next field in the form to become active (leaving the field that I was editing) - like TAB does. If I want carriage return/line feed I have to type CTRL-Enter. Is there a way to cause carriage return/line feeds to be put into a form text box using just the Enter key? This may seem like a small thing but others use this form too and hitting just Enter (for CR/LF) is a hard habit to break. Thanks, Will |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Will,
Bit tricky to get vbCrLf inserted in correct position and re-setting the cursor position if Enter is pressed in the middle of the text. Anyway have a go with this and see how you get on Private Declare Function GetKeyState32 Lib "user32" _ Alias "GetKeyState" (ByVal vKey As Integer) As Integer Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) Dim i As Long, n As Long, cnt As Long Dim nSelPos As Long Dim sText As String Dim by() As Byte If GetKeyState32(vbKeyReturn) < 0 Then '-128, enter pressed Cancel = True ' abort update nSelPos = TextBox1.SelStart 'cursor pos sText = TextBox1.Text If Len(sText) Then ' problem: vbCrLf is two characters but seems ' .SelStart does not count the Cr character ' need to count no. of Chr(13)'s before cursor ' for each chr(13) need to add an extra character count ' left of cursor, complicated 'cos need to increase length ' of the left portion of the string during the search. ' Could use Instr but I like this byte array approach! by = sText n = nSelPos * 2 - 1 Do While i <= n If by(i) = 13 Then n = n + 2 cnt = cnt + 1 End If i = i + 1 ' 2 bytes/char, interested in every other byte Loop End If sText = Left(sText, nSelPos + cnt) & _ vbCrLf & _ Mid(sText, nSelPos + 1 + cnt, Len(sText)) TextBox1.Text = sText TextBox1.SelStart = nSelPos + 1 End If End Sub Don't forget to set MultiLine & WordWrap prop's to True Regards, Peter T "roadkill" wrote in message ... I'm using a form with VBA and the form has several text boxes. When entering information I need to be able to put carriage return/line feeds into the text. However just hitting the Enter key causes the next field in the form to become active (leaving the field that I was editing) - like TAB does. If I want carriage return/line feed I have to type CTRL-Enter. Is there a way to cause carriage return/line feeds to be put into a form text box using just the Enter key? This may seem like a small thing but others use this form too and hitting just Enter (for CR/LF) is a hard habit to break. Thanks, Will |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Just seen RBS's EnterBehaviour tip, Aaaaargh !
ignore all this below Peter T "Peter T" <peter_t@discussions wrote in message ... Hi Will, Bit tricky to get vbCrLf inserted in correct position and re-setting the cursor position if Enter is pressed in the middle of the text. Anyway have a go with this and see how you get on Private Declare Function GetKeyState32 Lib "user32" _ Alias "GetKeyState" (ByVal vKey As Integer) As Integer Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) Dim i As Long, n As Long, cnt As Long Dim nSelPos As Long Dim sText As String Dim by() As Byte If GetKeyState32(vbKeyReturn) < 0 Then '-128, enter pressed Cancel = True ' abort update nSelPos = TextBox1.SelStart 'cursor pos sText = TextBox1.Text If Len(sText) Then ' problem: vbCrLf is two characters but seems ' .SelStart does not count the Cr character ' need to count no. of Chr(13)'s before cursor ' for each chr(13) need to add an extra character count ' left of cursor, complicated 'cos need to increase length ' of the left portion of the string during the search. ' Could use Instr but I like this byte array approach! by = sText n = nSelPos * 2 - 1 Do While i <= n If by(i) = 13 Then n = n + 2 cnt = cnt + 1 End If i = i + 1 ' 2 bytes/char, interested in every other byte Loop End If sText = Left(sText, nSelPos + cnt) & _ vbCrLf & _ Mid(sText, nSelPos + 1 + cnt, Len(sText)) TextBox1.Text = sText TextBox1.SelStart = nSelPos + 1 End If End Sub Don't forget to set MultiLine & WordWrap prop's to True Regards, Peter T "roadkill" wrote in message ... I'm using a form with VBA and the form has several text boxes. When entering information I need to be able to put carriage return/line feeds into the text. However just hitting the Enter key causes the next field in the form to become active (leaving the field that I was editing) - like TAB does. If I want carriage return/line feed I have to type CTRL-Enter. Is there a way to cause carriage return/line feeds to be put into a form text box using just the Enter key? This may seem like a small thing but others use this form too and hitting just Enter (for CR/LF) is a hard habit to break. Thanks, Will |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Good exercise though.
RBS "Peter T" <peter_t@discussions wrote in message ... Just seen RBS's EnterBehaviour tip, Aaaaargh ! ignore all this below Peter T "Peter T" <peter_t@discussions wrote in message ... Hi Will, Bit tricky to get vbCrLf inserted in correct position and re-setting the cursor position if Enter is pressed in the middle of the text. Anyway have a go with this and see how you get on Private Declare Function GetKeyState32 Lib "user32" _ Alias "GetKeyState" (ByVal vKey As Integer) As Integer Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) Dim i As Long, n As Long, cnt As Long Dim nSelPos As Long Dim sText As String Dim by() As Byte If GetKeyState32(vbKeyReturn) < 0 Then '-128, enter pressed Cancel = True ' abort update nSelPos = TextBox1.SelStart 'cursor pos sText = TextBox1.Text If Len(sText) Then ' problem: vbCrLf is two characters but seems ' .SelStart does not count the Cr character ' need to count no. of Chr(13)'s before cursor ' for each chr(13) need to add an extra character count ' left of cursor, complicated 'cos need to increase length ' of the left portion of the string during the search. ' Could use Instr but I like this byte array approach! by = sText n = nSelPos * 2 - 1 Do While i <= n If by(i) = 13 Then n = n + 2 cnt = cnt + 1 End If i = i + 1 ' 2 bytes/char, interested in every other byte Loop End If sText = Left(sText, nSelPos + cnt) & _ vbCrLf & _ Mid(sText, nSelPos + 1 + cnt, Len(sText)) TextBox1.Text = sText TextBox1.SelStart = nSelPos + 1 End If End Sub Don't forget to set MultiLine & WordWrap prop's to True Regards, Peter T "roadkill" wrote in message ... I'm using a form with VBA and the form has several text boxes. When entering information I need to be able to put carriage return/line feeds into the text. However just hitting the Enter key causes the next field in the form to become active (leaving the field that I was editing) - like TAB does. If I want carriage return/line feed I have to type CTRL-Enter. Is there a way to cause carriage return/line feeds to be put into a form text box using just the Enter key? This may seem like a small thing but others use this form too and hitting just Enter (for CR/LF) is a hard habit to break. Thanks, Will |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
:-), in a gritted teeth kind of way!
Silly really, I knew about EnterKeyBehavior and even have it in one of my app's, but forgot... Regards, Peter T "RB Smissaert" wrote in message ... Good exercise though. RBS |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Still, it may have given somebody a good laugh.
RBS "Peter T" <peter_t@discussions wrote in message ... :-), in a gritted teeth kind of way! Silly really, I knew about EnterKeyBehavior and even have it in one of my app's, but forgot... Regards, Peter T "RB Smissaert" wrote in message ... Good exercise though. RBS |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
What does Ctrl+Shift+Enter do? How does it differ from Enter? | Excel Programming | |||
What does hitting Ctrl + Shift + Enter to enter a formula do??? Help a n00b out. | Excel Worksheet Functions | |||
ctrl+shift+enter vs enter | Excel Discussion (Misc queries) | |||
HELP! I Lost The Ability To Advance From TextBox To TextBox With the ENTER Or The TAB Keys | Excel Programming | |||
how to enter 'CTRL-SHIFT-ENTER' in vb | Excel Programming |