Search for Style Separator

A

Angie M.

Hello,

Is there a way to replace paragraph marks formatted with the Hidden font
attribute with Style Separators? Here's my best try:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Font.Hidden = True
.Replacement.Application.Selection.InsertStyleSeparator
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

It find the hidden paragraph mark but doesn't insert the Style Seperator. I
couldn't figure out how else to do it, since the style sep is only available
from the selection object.

Thanks for your help.
 
C

Chip Orange

Angie,

Check out the help topic for the InsertStyleSeparator Method
of the Selection object. It has a loop which runs through the paragraphs
of a document, replacing certain paragraphs by inserting a style separator
manually.

Perhaps this indicates it can't be done with find/replace, or perhaps it's
just an alternate way of doing it.

HTH,

Chip
 
K

Klaus Linke

Hi Angie,

It seems you can't simply replace hidden paragraph marks with style
separators... bummer.

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Font.Hidden = True
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWildcards = False
End With
While Selection.Find.Execute
If Not Selection.Paragraphs(1).IsStyleSeparator Then
Selection.InsertStyleSeparator
End If
Wend

The "If ... Then" probably isn't strictly necessary, but searching for
hidden paragraph marks matches existing style separators too, and I wanted
to avoid complications and unnecessary replacements.

IMO, the style separator is a neat idea that was implemented badly. Among
the other things I don't understand about the implementation:
-- With thousands of "private use" Unicode characters available, why does
the style separator have the same code as the paragraph mark?
-- Why does it use "hidden" as manual character formatting (which is easy to
remove accidentally)?
-- Why (as you remarked) can it only be inserted in that silly way using the
selection?

Regards,
Klaus
 
D

dedawson

Hmmm. Well, I guess we learn something new every day. Although, I
must confess I'm still not clear on why one would want to do this.
Having multiple paragraph styles associated with a single paragraph
seems to go against the whole concept of using styles to make document
maintenance and consistency easier. Earlier portions of this thread
have already shown the havoc they can wreak on VBA.
 
J

Jennifer Thomas

Thanks for this code, Klaus - I'm in a legal environment too, and this is incredibly helpful!
 

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