I want to colorize a word with underscore inside

L

le Nordiste

Bonjour or hello,


I want to work on SQL text as SELECT * INTO T_My_Table_02 ……

I want to colorize in red the table name T_My_Table_02.
In the full document there are many sequences as SELECT * INTO
T_My_Table_n.

Word VBa assume T_My_Table_n are different words due to the
underscores.
How to bypass this Pb?

Thank in anticipation
 
D

David Sisson

Sub ChangeColor()

Dim aDoc As Document
Dim Rng As Range
Dim lCount As Long

Set aDoc = ActiveDocument

For lCount = 1 To 99

Set Rng = aDoc.Range

Do
With Rng.Find
.ClearFormatting
.Text = "SELECT * INTO T_My_Table_" & Format(lCount,
"00")
.Format = False
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = False
.Execute
End With

If Rng.Find.Found Then
Rng.Font.ColorIndex = wdRed
End If

Loop While Rng.Find.Found

Next
End Sub
 

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

Top