replacing different highlightings with different symbols

F

francvs

Hi everybody,

I need to print a lengthy word document with many highlightings with
different colors. As the printer is preventing me from distinguishing
one color from another, I'd like to have a macro which replaces the
highlighting with some conventional text to recognize it: e.g.: red
highlighting with a "[[" and a "]]" at the beginning and end of the
highlighted text, "((" and "))" for yellow highlighting, etc.
I know I should go and read tech docs for word, but now I'm in a
hurry... any help would be greatly appreciated.
Thanks
 
J

Jezebel

With ActiveDocument.Content.Find
.ClearFormatting
.Highlight = True

Do While .Execute

Select Case .Parent.HighlightColorIndex
Case wdRed
.Parent = "[[" & .Parent & "]]"
Case wdYellow
.Parent = "[[" & .Parent & "]]"

' ... Insert any other colors here ...

Case Else
msgbox "Whoops, missed a color"

End Select
Loop

End With
 
F

francvs

I have slightly modified the macro in order to simply delete all red
highlightings.

With ActiveDocument.Content.Find
.ClearFormatting
.Highlight = True

Do While .Execute

Select Case .Parent.HighlightColorIndex
Case wdRed
.Parent = ""
End Select
Loop

End With

Unfortunately, this code does not work if a _partially_ red string (for
example, a red and then green highlighted string, with no separating,
not highlighted spaces between the two colors) is encountered. Any hint
to delete the red part in this case?

thank you in advance
 
H

Helmut Weber

Hi,

how about this one:

Sub Test5003xy()
Dim rDcm As Range
Dim rtmp As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Highlight = True
While .Execute
rDcm.Select ' for testing, remove later
For Each rtmp In rDcm.Characters
If rtmp.HighlightColorIndex = wdRed Then
rtmp.Text = ""
End If
Next
Wend
End With
End Sub

There are other ways, of course.
The sample should work with any random
combinations of highlighted text.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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