#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
You would do better to format the client's name in a unique character or paragraph Style, then use a STYLEREF field in the header to refer to that Style. No code needed.
Are you sure the Section specified by ActiveDocument.Sections(i) exists when the code is run?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
headings, input boxes, word macros |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Templates headings | protocoder | Word | 6 | 05-14-2014 03:11 PM |
Column Headings | cinque8 | Word | 2 | 06-25-2012 06:15 PM |
Captioning with different Headings | judicial85 | Word | 3 | 03-05-2012 05:06 PM |
Headings | Metamag | Word | 5 | 04-16-2011 09:30 PM |
sub headings | mahound | Word | 2 | 08-20-2008 12:55 PM |