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 / September 2006

Tip: Looking for answers? Try searching our database.

Modifing the Header and Footer content

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeffery B Paarsa - 27 Sep 2006 07:01 GMT
Hello,

Is there any way to modify the content of Header and Footer on a Template?  
I have two almost identical templates for two different office locations.  
The differences are the Office address on the Header and the Phone/Fax
numbers on the footer.  I wonder if there is a way I merge these two
templates into one but based on an external file be able to merge or pull the
external file and update the header and footer on the templates.

Signature

Jeff B Paarsa

Graham Mayor - 27 Sep 2006 11:05 GMT
You could insert an IncludeText field in place of the address to call
bookmarks from a document saved on a local disc eg

{ INCLUDETEXT  "d:\\My Documents\\Test\\Merge\\Address.doc" address
\*charformat}
in the header for the address and
{ INCLUDETEXT  "d:\\My Documents\\Test\\Merge\\Address.doc" address
\*charformat}
in the footer for the fax number

where the address bookmark contains the local address and faxno the fax
number

Then with an autonew macro in the document's template, based on Dave Lett's
code from another post today, you could unlink the two fields to ensure that
new letters produced from the template are not updated subsequently at a
different location to show the wrong address and fax number.

The following will unlink that particular field. Other fields in the
document are not unlinked.

Dim iFld As Integer
For iFld = ActiveDocument.Sections(1).Headers(1).Range.Fields.Count To 1
Step -1
   With ActiveDocument.Sections(1).Headers(1).Range.Fields(iFld)
       If .Type = wdFieldIncludeText Then
           If InStr(1, .Code, "Address.doc") <> 0 Then
               .Unlink
           End If
       End If
   End With
Next iFld
For iFld = ActiveDocument.Sections(1).Footers(1).Range.Fields.Count To 1
Step -1
   With ActiveDocument.Sections(1).Footers(1).Range.Fields(iFld)
       If .Type = wdFieldIncludeText Then
           If InStr(1, .Code, "Address.doc") <> 0 Then
               .Unlink
           End If
       End If
   End With
Next iFld

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Hello,
>
[quoted text clipped - 6 lines]
> able to merge or pull the external file and update the header and
> footer on the templates.
Jeffery B Paarsa - 27 Sep 2006 18:28 GMT
Hello,

I think I am confused and I did not understand what you explained to me.  
Let me tell you what I did base on my understanding.
1. On the footer area of my template .dot I put the following two lines:
    {INCLUDETEXT “G:\\Maryam doc\\SFooter.doc” FootAddl1 \*charformat}
    {INCLUDETEXT “G:\\Maryam doc\\SFooter.doc” FootAddl2 \*charformat}
2. I created a new document called SFooter.doc with 2 line of text as follow:
           1111 XXXX Rd. Suite E   Phone: (999)555-1212  Bookmark id
FootAddl1
           ZZZ City, XX 999999 Fax:     (999)555-1212        Bookmark id
FootAddl2
Now any time I double click on my Temple .dot a new document will be created
but does not bring in the addresses stored on the Bookmarks FootAddl1 &
FootAddl2 on the SFooter.doc.  What am I doing wrong?  Well you instructed
local disk, my G drive is a USB that I don’t think makes the difference.  
Thanks for your help.

Signature

Jeff B Paarsa

> You could insert an IncludeText field in place of the address to call
> bookmarks from a document saved on a local disc eg
[quoted text clipped - 49 lines]
> > able to merge or pull the external file and update the header and
> > footer on the templates.
Graham Mayor - 28 Sep 2006 06:39 GMT
Did you insert the fields from the dialog or did you type them using CTRL+F9
for the field boundaries (you also have smart quotes which should be changed
for ordinary quotes).

If so, add the following macro to the document template to force an update
to the field each time a new document is created.

Sub autonew()
Dim oField As Field
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter

For Each oSection In ActiveDocument.Sections
   For Each oHeader In oSection.Headers
       If oHeader.Exists Then
           For Each oField In oHeader.Range.Fields
               oField.Update
           Next oField
       End If
   Next oHeader
   For Each oFooter In oSection.Footers
       If oFooter.Exists Then
            For Each oField In oFooter.Range.Fields
                oField.Update
           Next oField
       End If
   Next oFooter
Next oSection
End Sub

> Hello,
>
[quoted text clipped - 79 lines]
>>> able to merge or pull the external file and update the header and
>>> footer on the templates.
Jeffery B Paarsa - 28 Sep 2006 21:46 GMT
Hello,

Actually I had typed them at first and that’s why it was not working…When I
used the dialog for inserting the INCLUDETEXT this time after I received your
response I made it to work right at the time of editing the template .dot
file.  So the bookmarks was brought in from the secondary file but I noticed
that after saving the template .dot file when I double click on the template
.dot file and a new .doc file is created still the Header and Footer holds
the same data that it had been saved at the time of saving the template .dot
file even though that I had updated the content of the bookmarks on the
secondary file.  

Yes you gave me a routine to be put on AutoNew subroutine which updates and
refreshes the Header and Footer area and that is great but sometimes I create
these document without using AutoNew Macro by invoking:

 Dim MedHist As Document

 WordBasic.DisableAutoMacros 1

 Set MedHist = Word.Documents.Add(Template:="D:\M
doc\(ALL)MRPMedHistory.dot", Visible:=False)

 With MedHist …..

How can I get the Header and Footer updated in those situations?  Should I
put this suggested routine within "With MidHist"?

Bottom line you are great no matter if you don’t have a solution for this
situation.

Signature

Jeff B Paarsa

> Did you insert the fields from the dialog or did you type them using CTRL+F9
> for the field boundaries (you also have smart quotes which should be changed
[quoted text clipped - 110 lines]
> >>> able to merge or pull the external file and update the header and
> >>> footer on the templates.
 
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.