Is there a quick way to check highlight in a paragraph?

K

Ken Wan

Hi,
I am working on a parser of Word document in the following way:
for each aPara in ActiveDocument.paragraphs
Do something ...
Next aPara.
One of the things I need to do is to locate all highlighted characters. Is
there a quick way to decide if a paragraph contain any highlighted
characters? By highlight, I mean any of bold, italic, underline, or colours.
Thanks in advance for your help.
Ken
 
J

Jonathan West

Hi Ken

Try this

For each aPara in ActiveDocument.Paragraphs
Select Case aPara.Range.Font.Bold
Case 0
'none of the text is bold
Case -1
'all of the text is bold
Case Else
'some of the text is bold
End Select
Next aPara

The key is that if there is a mixed format in the text being checked, the
value returned by the Bold property is 9999999.

You can do much the same thing with the other character formatting.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 
H

Helmut Weber

Hi Ken,
I think the most important thing is to make some
presuppostions, like:
There are no embossed charaters in all of doc.
There are no animated charaters in all of doc.
If that is not possible, then there is a lot
of coding to do, like this:
Sub CheckforFormat()
' wdUndefined = 9999999
Dim sD As String
Dim rD As Range
Set rD = ActiveDocument.Range
sD = "00000000000000"
With rD.Font
If .StrikeThrough = wdUndefined Then
Mid$(sD, 1, 1) = "1"
End If
If .DoubleStrikeThrough = wdUndefined Then
Mid$(sD, 2, 1) = "1"
End If
If .Superscript = wdUndefined Then
Mid$(sD, 3, 1) = "1"
End If
If .Subscript = wdUndefined Then
Mid$(sD, 4, 1) = "1"
End If
If .Shadow = wdUndefined Then
Mid$(sD, 5, 1) = "1"
End If
If .Outline = wdUndefined Then
Mid$(sD, 6, 1) = "1"
End If
If .Emboss = wdUndefined Then
Mid$(sD, 7, 1) = "1"
End If
If .Engrave = wdUndefined Then
Mid$(sD, 8, 1) = "1"
End If
If .SmallCaps = wdUndefined Then
Mid$(sD, 9, 1) = "1"
End If
If .AllCaps = wdUndefined Then
Mid$(sD, 10, 1) = "1"
End If
If .Hidden = wdUndefined Then
Mid$(sD, 11, 1) = "1"
End If
If .Bold = wdUndefined Then
Mid$(sD, 12, 1) = "1"
End If
If .Italic = wdUndefined Then
Mid$(sD, 13, 1) = "1"
End If
If .Animation = wdUndefined Then
Mid$(sD, 14, 1) = "1"
End If
End With
Msgbox sD
End Sub
These are by far not all possibilities nor gotchas.
But you can exclude some formatting from searching for it.
Repeat the process for paragraph.ranges.

Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 

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