PDA

View Full Version : Find the cursor position in a string



mikke3141
03-29-2010, 12:14 AM
Hello,

Is there any way to show e.g. with Application.StatusBar in front of which character I have my cursor?

A have long 400 charachter string in each excel cell and I would easily need to find the location in which place each character is by placing my cursor on the character.

Thank you for your help.

Jan Karel Pieterse
03-29-2010, 03:57 AM
You could add a textbox control from the Control toolbox which points to the cell in question and attach this code to it:

Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Application.StatusBar = TextBox1.SelStart
End Sub

Aussiebear
03-29-2010, 04:53 AM
Could you explain what the selstart does please?

Jan Karel Pieterse
03-29-2010, 06:52 AM
It returns the starting position of the selected text in an ActiveX textbox from the control toolbox.

SamT
03-29-2010, 07:57 PM
Selstart is not in my xl2003 helpfile

Jan Karel Pieterse
03-30-2010, 02:52 AM
If I type selstart into the helpbox of the VBA editor, this is what I get:

SelStart Property


Indicates the starting point of selected text, or the insertion point if no text is selected.
Syntax
object.SelStart [= Long]
The SelStart property syntax has these parts:
PartDescriptionobjectRequired. A valid object.LongOptional. A numeric expression specifying the starting point of text selected. For SelLength and SelStart, the valid range of settings is 0 to the total number of characters in the edit area of a ComboBox or TextBox. The default value is zero.

Remarks
The SelStart property is always valid, even when the control does not have focus (javascript:hhobj_5.Click()). Setting SelStart to a value less than zero creates an error. Attempting to set SelStart to a value greater than the number of characters available in a control results in a value equal to the number of characters in the control.
Changing the value of SelStart cancels any existing selection in the control, places an insertion point in the text, and sets the SelLength property to zero.

SamT
03-30-2010, 07:05 AM
Thanks Jan,

I usually access the help file by typing the word I want help for into the VBE and hitting the F1 key. This only searches the VBE and Excel-VBA helps.

Opening a UserForm Code page and doing the above does bring up the SelStart Help. :)