Thread: [Solved] VBA for Headings
View Single Post
 
Old 06-09-2015, 11:06 AM
spc94 spc94 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jun 2015
Location: Ohio, USA
Posts: 8
spc94 is on a distinguished road
Default VBA for Headings

I want to input the clients name and then have if fill in the template where I have put the (CLIENT NAME) place holder. When I delete the headers portion of the code it works but when I run it with it I get a " The requested member of the collection does not exist" Error. Any suggestions on how to fix?

strSubName = InputBox("Enter Client Name")

OldWord = "(CLIENT NAME)"
NewWord = strSubName

With ActiveDocument.Content.Find
.Forward = True
.Wrap = wdFindStop
.Execute FindText:=OldWord, ReplaceWith:=NewWord, Replace:=wdReplaceAll, MatchCase:=True
End With

With ActiveDocument.Sections(i).Headers(1).Range.Find
.Text = "(CLIENT NAME)"
.Replacement.Text = strSubName
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Reply With Quote