Modifing the Header and Footer content

J

Jeffery B Paarsa

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.
 
G

Graham Mayor

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



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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jeffery B Paarsa

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.
 
G

Graham Mayor

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
 
J

Jeffery B Paarsa

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top