Chris Macro
Well-known Member
- Joined
- Nov 2, 2011
- Messages
- 1,345
- Office Version
- 365
- Platform
- Windows
Hi, I am trying to mimic how the VBA Editor changes commented text to green (with an apostrophe as the indicator) in a Word Document's text. I am approaching this by using the Find function to find all the apostrophe's in my selection and then select to the end of the line and change that selection to green. Unfortunately my code gets stuck in an infinite loop on the first line of my sample text. I believe this is because I am changing the selection range when I use the extend command. Anyone know how I can fix this code or maybe there is another way to approach my problem? Thanks for your time!
I have the following testing Text:
Here is my code so far:
I have the following testing Text:
Code:
'Hello World
'It's my car!
Dim myOrgColor As Double 'original color of color index 32
Dim myNewColor As Double 'color that was picked in the dialogue
Dim myRGB_R As Integer ' RGB values of the color that will be
Dim myRGB_G As Integer 'displayed in the dialogue as
Dim myRGB_B As Integer 'It's my car!
Here is my code so far:
Code:
Sub Sample()
'~~> Loop through the array to get the search text
With Selection.Find
.ClearFormatting
.Text = "'"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Execute
'~~> Change the attributes
Do Until .Found = False
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Color = RGB(0, 128, 0)
Selection.Find.Execute
Loop
End With
End Sub