Textbox and Bullets
On Apr 16, 4:54 pm, Benz wrote:
I was wondering if it is possible in a Userform textbox with Multi-Line to
automaticaly inser " * " on every line of just to inser that where ever
the user clicked within the textbox and ran the specific macro.
Ben Z.
Assuming you have a form with TextBox1 as the text box, this event-
handler code will add the bullet when you press Shift-Enter, Ctrl-
Enter or Ctrl-Shift-Enter (which is what you have to do in Excel 2003
to get a new line in a text box, as far as can tell). It will only add
a bullet to the last line if you hold enter to put multiple new lines.
You can change the bullet const string to whatever bullet you want.
Option Explicit
Private Const bullet As String = "* "
Private Sub TextBox1_Enter()
With TextBox1
If .Text = Empty Then
.Text = bullet
End If
End With
End Sub
Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
If KeyCode = vbKeyReturn And Shift 0 And Shift < 4 Then
With TextBox1
Dim sel_idx As Integer
sel_idx = .SelStart
.Text = Left(.Text, .SelStart + .CurLine) & bullet &
Right(.Text, Len(.Text) - .SelStart - .CurLine)
.SelStart = sel_idx + Len(bullet)
End With
End If
End Sub
Enjoy,
David G
|