How to find style separator code through VBA?

M

Mike

In our company, we have a number of older documents that used hidden
paragraph marks instead of style separators. The purpose of both is to
separate headings from body text for easier generation of TOC. I am finding
a number of documents that have a combination - hidden paragraphs marks &
style separators - and it gets confusing to view these documents when hidden
paragraph marks turned on (pagination will change). While my routine works,
I do not like the fact that hidden paragraph marks & style separators do not
appear to be distinguishable programatically; visually you can tell the
difference because style separators have a light dotted frame around them.
I was wondering if there is a way to distinguish the style separator from
other codes.

TIA,
Mike

Sub HiddenParaToStyleSep()
Selection.HomeKey Unit:=wdStory
' Find hidden paragraph
With Selection.Find
.ClearFormatting
.Text = "^p"
.Font.Hidden = True
.Forward = True
While .Execute
' Replace hidden paragraph with auto color, unhide
With Selection.Font
.Hidden = False
.Color = wdColorAutomatic
End With
' Insert style separator
Selection.InsertStyleSeparator
Wend
End With
End Sub
 
M

Mike

I *thought* I had seen an 'IsStyleSeparator' property! I have tested this
on a couple different documents and - at least so far - it has worked as
expected. Where I work, this will be a big time saver; it allows documents
with hidden paragraphs marks (used pre-Word 2002, as well as by some people
who are not yet familiar with style separators) to quickly be updated with
style separators.

Mike

Sub HiddenParaToStyleSep()
Selection.HomeKey Unit:=wdStory
' Find hidden paragraph
With Selection.Find
.ClearFormatting
.Text = "^p"
.Font.Hidden = True
.Forward = True
While .Execute
' If hidden paragraph is Style Separator, do not replace
If Selection.Paragraphs(1).IsStyleSeparator = False Then
' Replace hidden paragraph with auto color, unhide
With Selection.Font
.Hidden = False
.Color = wdColorAutomatic
End With
' Insert style separator
Selection.InsertStyleSeparator
End If
Wend
End With
End Sub

Mike
 

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