Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Style in word and replace with another style help

Status
Not open for further replies.

sonname

Programmer
May 18, 2001
115
US
Hi,
This should be simple, but the macro that I recorded does not work when I try to run it. What I want to do is find the "Normal" style in a document and replace it with the "Heading 2" style. Here is the macro. It worked when I recorded the macro, but does not work when I try to run the same code in a procedure. Should I be using something other than the Selection object?

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Normal")
Selection.Find.ParagraphFormat.Borders.Shadow = False
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Heading 2")
Selection.Find.Replacement.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
 
What I want to do is find the "Normal" style in a document and replace it with the "Heading 2" style. "

If this is true and accurate...
Code:
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
   If oPara.Style = "Normal" Then
      oPara.Style = "Heading 2"
   End If
Next
Done.

The above just exactly that...makes each paragraph that is "Normal" style into "Heading 2" style.

Literally.

However, I somehow doubt if this is precisely what you want to do. If it is, that you literally want to make each Normal into Heading 2, then the above code does exactly that.

If it is not, there is something else - some logic other than simply switching all Normal to Heading 2 - then you will have to state what is that logic.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top