Finding text based on paragraph style - doesn't work?

  • Thread starter Thread starter Paul Moloney
  • Start date Start date
P

Paul Moloney

I was attempted to write a macro (in Word 2003 SP2) which would apply
a paragraph style to a line based on its indentation. So I thought I
would start as usual by recording the macro then editing it down.

However, when I tried a Find, with the "Find What" field empty, but
with the parameter Format->Paragraph->Indentation Left set to 5.71cm,
on a document containing a line with such an indentation, it doesn't
find it.

I even tried it with a "Find What" field value of "heading", with a
line in the document containing the word "heading" and with an
indentation of 5.71cm. This also didn't work.

Is there a correct way to do this?

Thanks,

P.
 
If you were using the macro recorder, it's buggy. It records the Find, but
neglects to include anything about the formatting you specified. The articlehttp://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htmexplains how
to modify the macro.

Hi Jay,

The problem isn't related to re-running the macro; it's to do with the
Find command. Note the above behaviour happens even when I'm not
recording a macro; the Find command simply won't find text based on
its paragraph indentation.

Regards,

P.
 
I also tried creating a macro from scratch, without recording. This
_should_ work as far as I know, but doesn't find anything:

Sub Macro1()

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.ParagraphFormat.LeftIndent = CentimetersToPoints(10)
.Replacement.ParagraphFormat.LeftIndent =
CentimetersToPoints(1)
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
 
I can affirm that Find does work when searching for Indent formatting (with
Find what: blank, or with Find what: containing any text with the
corresponding Indent applied).

So... the question is WHY it's not working for you.

Try starting Word with the /a switch (start - run - winword.exe /a). Set up
a simple scenario -- 1 cm left indent (for example), and see if Find finds
it.
 
After much messing around, I finally discovered why this wasn't
working for me; it may be related to the way Word rounds numbers when
displaying them.

When I imported the text I wanted to manipulate into a fresh Word
document, the parameter left indent for certain lines shows up as
0.63cm (roughly 1/4 inch) when I select the text and displayed Format-
Paragraph.

So my macro searched for lines with an left indent of 0.63cm; this
didn't work.

However, a left-indent of 0.635 _did_ work.

The same for lines of 1.9cm (~3/4 inch); searching for lines of 1.9cm
didn't work, but 1.905cm did.

So the number displayed for the indentation in the Format->Paragraph
box for imported text appears to be a rounded value rather than the
actual value.

Hope this is of some use to someone,

Regards,

P.
 
Indeed, 1/4 in equals exactly 0.635 cm; and 3/4 in = 1.905 cm.

--
Stefan Blom
Microsoft Word MVP


in message
 
Back
Top