Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-09-2015, 11:06 AM
spc94 spc94 is offline VBA for Headings Windows 7 64bit VBA for Headings Office 2010 64bit
Novice
VBA for Headings
 
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
  #2  
Old 06-09-2015, 04:06 PM
macropod's Avatar
macropod macropod is offline VBA for Headings Windows 7 64bit VBA for Headings Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft