Textbox and Bullets

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
This works great!! Thank you David.

David G said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top