Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Replace footer text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve C - 23 Jan 2008 23:12 GMT
I need my code to be able to search a footer section for the text "<Project
#>" in a multiple page, single section document and replace it with the value
of a variable (ProjNum) provided from a user form.  Can someone help me out?  
Thanks!
Signature

Steve C

Lene Fredborg - 24 Jan 2008 00:07 GMT
You will find a macro (function) below that should do the job. Some comments
first:

1. Three different footers exist: first page footer, primary footer, even
page footer. In the macro, I have assumed your footer is a "primary footer" –
it is if the document does not have "Different first page" and "Different odd
and even" turned on in File > Page Setup > Layout tab.

2. In a document with more than one section, the macro will only replace
text in the footer of section 1.

3. The function has a parameter, sReplacement. When calling the function,
sReplacement must be set to the value of ProjNum (supposed to be a string).
You can use the following line of code to call the function:

ReplaceTextInFooter sReplacement:=ProjNum

This will execute the function below. The function can be placed in any
module.

Function ReplaceTextInFooter(sReplacement As String)
   Dim oRange As Range
   
   Set oRange =
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
   With oRange.Find
       .Text = "<Project #>"
       .Replacement.Text = sReplacement
       .Execute Replace:=wdReplaceAll
   End With
   
   Set oRange = Nothing
End Function

Signature

Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word

> I need my code to be able to search a footer section for the text "<Project
> #>" in a multiple page, single section document and replace it with the value
> of a variable (ProjNum) provided from a user form.  Can someone help me out?  
> Thanks!
Steve C - 24 Jan 2008 17:39 GMT
Lene,

Thanks so much for the help!  It is much appreciated.
Signature

Steve C

> You will find a macro (function) below that should do the job. Some comments
> first:
[quoted text clipped - 34 lines]
> > of a variable (ProjNum) provided from a user form.  Can someone help me out?  
> > Thanks!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.