find and determine if its in bold, italic or normal

F

filo666

I have something to do a kind of difficult:

I have a document with a format like:

Basket: tre (in italic)., sd (bold)., hg(normal)., more words that I dont care

red: tre (bold)., more words that I dont care., sd (norma).,

and so on

what I want is that if the basket paragraph contains tre in italic then
var1=1, if tre is in bold, then var1=2 and if its normal then var1=3; I also
want to do the same with sd and hg, how to accomplish this (it could be the
case that tre is not on the list, and also that the 3 of them are not in the
list)

TIA
 
H

Helmut Weber

Hi Filo

in case of a kind of difficult,
the solutions provided need a bit more of adapting :-;

Have a look at this one:

Sub Test40Z()
Dim rDcm As Range ' documents range
Dim rtmp As Range ' a temporary range
Dim oPrg As Paragraph ' a paragraph
Dim lngV As Long ' kind of formatting
Dim lngP As Long ' paragraph number
' -----------------------------------------
Set rDcm = ActiveDocument.Range
For Each oPrg In rDcm.Paragraphs
lngP = lngP + 1
If Left(oPrg.Range.Text, 8) = "Basket: " Then
Set rtmp = oPrg.Range.Duplicate
lngV = 0 ' not found
With rtmp.Find
.Text = "tre"
.Wrap = wdFindStop
If .Execute Then
lngV = 3 ' not bold, not italic
If rtmp.Font.Bold = True Then lngV = 1
If rtmp.Font.Italic = True Then lngV = 2
End If
Debug.Print lngP, .Text, lngV
End With
Set rtmp = oPrg.Range.Duplicate
lngV = 0 ' not found
With rtmp.Find
.Text = "hg"
.Wrap = wdFindStop
If .Execute Then
lngV = 3 ' not bold, not italic
If rtmp.Font.Bold = True Then lngV = 1
If rtmp.Font.Italic = True Then lngV = 2
End If
Debug.Print lngP, .Text, lngV
End With
End If
Next
End Sub

Not to mention that "tre" could be both bold and italic,
and could be found several times in the same paragraph.

Also, one could loop over an array of the text to be found
and output the paragraph which was searched
and whether the text was found
and whether the first occurence was bold
or whatever...

--
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