Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default highlight text in userform textbox

How would I highlight a certain character in a plain multiline textbox on a
userform
given the line number and the character number in that line?

So for example given this text:

This is a test.
Trying to highlight.

and given line number 2 and character number 15
the character l in the second line would be highlighted.

RBS

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default highlight text in userform textbox

Not the most elegant method perhaps, but it does work:


Option Explicit

Private Sub UserForm_Initialize()

TextBox1.Text = "0 - Option Explicit" & vbCrLf & _
"1 - Option Compare Binary" & vbCrLf & _
"2 - Public IDWhereSQL As String" & vbCrLf & _
"3 - Public DoAddress As Boolean" & vbCrLf & _
"4 - Public DoPhone As Boolean" & vbCrLf & _
"5 - Private IDSelectSQL As String" & vbCrLf & _
"6 - Private IDFromClause As String" & vbCrLf & _
"7 - Private DoIDFromClause As Boolean"

TextBox2.Text = "2"
TextBox3.Text = "0"

End Sub


Private Sub CommandButton1_Click()

Dim i As Long
Dim lCurXStart As Long
Dim lChar As Long
Dim lLineToReach As Long
Dim lCharToReach As Long

lLineToReach = Val(TextBox2.Text)
lCharToReach = Val(TextBox3.Text)

With TextBox1

.SetFocus
.SelStart = 0

'this is the position at the
'very left margin of the textbox
'---------------------------------------
lCurXStart = .CurX

Do Until (.CurLine = lLineToReach And _
lChar = lCharToReach) Or i = Len(.Text)

.SelStart = i
lChar = lChar + 1
i = i + 1

'reset the lChar at the left margin
'----------------------------------
If .CurX = lCurXStart Then
lChar = 0
End If

DoEvents
Loop

.SelLength = 1

End With

End Sub


RBS


"RB Smissaert" wrote in message
...
How would I highlight a certain character in a plain multiline textbox on
a userform
given the line number and the character number in that line?

So for example given this text:

This is a test.
Trying to highlight.

and given line number 2 and character number 15
the character l in the second line would be highlighted.

RBS


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Highlight all Text in a Textbox when the textbox is selected RPIJG[_73_] Excel Programming 3 October 28th 05 08:28 PM
Using The Text From A Textbox In A UserForm Donna[_7_] Excel Programming 2 February 24th 05 03:25 PM
Qn: Display Text in TextBox in Userform Michael Vaughan Excel Programming 1 August 18th 04 05:06 PM
formatting text in TextBox in UserForm Kevin Excel Programming 2 November 7th 03 01:34 PM
UserForm TextBox to ActiveSheet TextBox over 256 characters Dan E[_2_] Excel Programming 1 July 28th 03 07:36 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"