footer macro

J

Jay Freedman

How do I create a macro to insert a footer at the bottom
of the page?

Hi Gil,

I'm afraid your question isn't framed very well.

First, if you're using Word's features as they were designed, it
usually isn't necessary to insert a footer with a macro at all. You
create a template for a particular type of document, and you insert
the footer manually into the template. Then every document based on
the template will inherit the same footer. If the footer text needs to
be different for each document (dates, pages, etc.) you include fields
to display those things.

If you really do need to create a footer through a macro, perhaps
because you're using automation of Word from another program, you need
to understand that each section in a Word document can have up to
three footers -- the main footer, the first-page footer, and the
even-page footer -- depending on which options are chosen in File >
Page Setup > Layout. Which footer(s) in which section(s) do you want
to create?

Finally, what do you want to put into the footer?

For the simplest case of placing constant text into the main footer of
section 1, the code would be

ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text _
= "Footer text"
 
G

Gil

Jay

Sorry for not elaborating. I work in a small group of 9
employees. Some of my fellow employees are not that savvy
to find their document locations where it is saved. So
they ask me if it possible to create a macro button that
creates a footer with the document name and location. I
have used the following script in excel before.

Sub UpdateFooter()
ActiveSheet.PageSetup.LeftFooter=ActiveWorkbook.FullName

How do I change your script if I need the document name
and location? In advance thank for your help

Gil
-----Original Message-----


Hi Gil,

I'm afraid your question isn't framed very well.

First, if you're using Word's features as they were designed, it
usually isn't necessary to insert a footer with a macro at all. You
create a template for a particular type of document, and you insert
the footer manually into the template. Then every document based on
the template will inherit the same footer. If the footer text needs to
be different for each document (dates, pages, etc.) you include fields
to display those things.

If you really do need to create a footer through a macro, perhaps
because you're using automation of Word from another program, you need
to understand that each section in a Word document can have up to
three footers -- the main footer, the first-page footer, and the
even-page footer -- depending on which options are chosen in File >
Page Setup > Layout. Which footer(s) in which section(s) do you want
to create?

Finally, what do you want to put into the footer?

For the simplest case of placing constant text into the main footer of
section 1, the code would be

ActiveDocument.Sections(1).Footers
(wdHeaderFooterPrimary).Range.Text _
 
J

Jay Freedman

Hi Gil,

This is a perfect example of what I was saying about making a template
with a footer containing a field.

Create a template (File > New, and select the Template option button
before clicking OK). Open the template's footer (assuming you don't
have any first-page or even-page footer, you'll be in the main
footer). On the Header/Footer toolbar, click the AutoText button and
select the "Filename and path" item. This inserts a field at the
cursor position, containing the field code {Filename \p} which
automatically shows the filename and path. Close the footer and save
the template (after adding anything else needed for this kind of
document).

When you use File > New and select this template as the basis for a
document, the filename and path will be there. No macro, no buttons,
no fuss.

To let everyone use this template, store it on the server in a folder
everyone can see. In Word's Tools > Options > File Locations dialog,
have each user modify the Worgroup Templates location to point to that
folder. Then the template will show up in their File > New dialog.
 
G

Gil

Thanks!

Gil
-----Original Message-----
Hi Gil,

This is a perfect example of what I was saying about making a template
with a footer containing a field.

Create a template (File > New, and select the Template option button
before clicking OK). Open the template's footer (assuming you don't
have any first-page or even-page footer, you'll be in the main
footer). On the Header/Footer toolbar, click the AutoText button and
select the "Filename and path" item. This inserts a field at the
cursor position, containing the field code {Filename \p} which
automatically shows the filename and path. Close the footer and save
the template (after adding anything else needed for this kind of
document).

When you use File > New and select this template as the basis for a
document, the filename and path will be there. No macro, no buttons,
no fuss.

To let everyone use this template, store it on the server in a folder
everyone can see. In Word's Tools > Options > File Locations dialog,
have each user modify the Worgroup Templates location to point to that
folder. Then the template will show up in their File > New dialog.

--
Regards,
Jay Freedman
Microsoft Word MVP



.
 
C

Chuck

Hi Gil

Your code suggests you're working in Excel, not Word so the procedure for
setting up a template would be different from what Jay suggested. If you
enter "Template" in Excel help you'll get the information you need to create
Excel templates with preset footers, etc.
 

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