View Single Post
  #1   Report Post  
Posted to microsoft.public.word.pagelayout
Mike
 
Posts: n/a
Default TOC helper - replace hidden paragraph with style separator

I work at a help desk with a large number of Word users and occassionally
run into the problem where users either are not familiar with using the
style separator (to assist in creating run-in headings so that only the
heading, not the body text, shows up in the TOC) or are older documents that
used hidden paragraph marks. Since multiple people can work on a document,
we sometimes end up with documents that partly use style separators and
partly use hidden paragraph marks - VERY confusing. So I created the
following script to replace the hidden paragraph mark with the style
separator (for Word 2002 & above).

Although this code has been working well for the past several days, we are
still testing it. If you would like to use it, PLEASE PLEASE PLEASE save
the document you are going to try it on first. Although I cannot imagine
why it would cause any problems, it is designed to replace items in the
document, so there is always the chance I may have overlooked something.

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