ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find position of cursor in text box (https://www.excelbanter.com/excel-programming/386678-find-position-cursor-text-box.html)

Adrian D. Bailey

Find position of cursor in text box
 
Is there a way I can determine the position of the cursor in a text box in a
custom form?

Reason - if the user has just typed a CR/LF I want the macro to add in a
bullet point.
I've made this happen when the cursor is at the end of the text by putting
the following in an On Change macro
if right(mytext,2) = chr(13) & chr(10) then mytext = mytext & chr(149) &
chr(32)
but I'm struggling for a method that works when the cursor is in the middle
of the text.

--
Adrian D.Bailey, Information and Systems Manager, Dept.Human Sciences
Loughborough University, Loughborough Leics, LE11 3TU, UK.
Tel: 01509 223007 Fax: 01509 223940

Community Warden, Storer and Burleigh Areas. Out-of-hours Tel: 01509 563263
--



Jim Rech

Find position of cursor in text box
 
SelStart should do it if I understand you.

Private Sub TextBox1_Change()
Debug.Print TextBox1.SelStart
End Sub


--
Jim
"Adrian D. Bailey" wrote in message
...
| Is there a way I can determine the position of the cursor in a text box in
a
| custom form?
|
| Reason - if the user has just typed a CR/LF I want the macro to add in a
| bullet point.
| I've made this happen when the cursor is at the end of the text by putting
| the following in an On Change macro
| if right(mytext,2) = chr(13) & chr(10) then mytext = mytext & chr(149) &
| chr(32)
| but I'm struggling for a method that works when the cursor is in the
middle
| of the text.
|
| --
| Adrian D.Bailey, Information and Systems Manager, Dept.Human Sciences
| Loughborough University, Loughborough Leics, LE11 3TU, UK.
| Tel: 01509 223007 Fax: 01509 223940
|
| Community Warden, Storer and Burleigh Areas. Out-of-hours Tel: 01509
563263
| --
|
|



Adrian D. Bailey

Find position of cursor in text box
 
Thanks Jim, just what I was looking for.

--
Adrian D.Bailey, Information and Systems Manager, Dept.Human Sciences
Loughborough University, Loughborough Leics, LE11 3TU, UK.
Tel: 01509 223007 Fax: 01509 223940

Community Warden, Storer and Burleigh Areas. Out-of-hours Tel: 01509 563263
--

"Jim Rech" wrote in message
...
SelStart should do it if I understand you.

Private Sub TextBox1_Change()
Debug.Print TextBox1.SelStart
End Sub


--
Jim
"Adrian D. Bailey" wrote in message
...
| Is there a way I can determine the position of the cursor in a text box
in
a
| custom form?
|
| Reason - if the user has just typed a CR/LF I want the macro to add in a
| bullet point.
| I've made this happen when the cursor is at the end of the text by
putting
| the following in an On Change macro
| if right(mytext,2) = chr(13) & chr(10) then mytext = mytext & chr(149) &
| chr(32)
| but I'm struggling for a method that works when the cursor is in the
middle
| of the text.
|
| --
| Adrian D.Bailey, Information and Systems Manager, Dept.Human Sciences
| Loughborough University, Loughborough Leics, LE11 3TU, UK.
|
Tel: 01509 223007 Fax: 01509 223940
|
| Community Warden, Storer and Burleigh Areas. Out-of-hours Tel: 01509
563263
| --
|
|






All times are GMT +1. The time now is 06:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com