Reformatting Header on Page 2 of 1-page document

P

Perky Penni

Using Word XP, VBA. I have been trying to figure out how to change the basic
page setup for the second page header on a letter template that, when
finished by the user, is a 1-page Word document. Currently, the second page
header has been set up with 3 fields which give the address, the date, and
page number. However, after that header was set up, then the template was
made a 1-pager. The letter is not any fixed size. It can be one page or
more than one page when someone adds the body of the letter. Now, when I try
to code for the second page to change the Header margin, I get an error
message that the collection doesn't exist. Here is the line of code that it
burps on.

ActiveWindow.ActivePane.View.SeekView = wdSeekPrimaryHeader

If anyone has any ideas, that would be great. Thanks.
 
J

Jean-Guy Marcil

Perky Penni was telling us:
Perky Penni nous racontait que :
Using Word XP, VBA. I have been trying to figure out how to change
the basic page setup for the second page header on a letter template
that, when finished by the user, is a 1-page Word document.
Currently, the second page header has been set up with 3 fields which
give the address, the date, and page number. However, after that
header was set up, then the template was made a 1-pager. The letter
is not any fixed size. It can be one page or more than one page when
someone adds the body of the letter. Now, when I try to code for the
second page to change the Header margin, I get an error message that
the collection doesn't exist. Here is the line of code that it burps
on.

ActiveWindow.ActivePane.View.SeekView = wdSeekPrimaryHeader

If anyone has any ideas, that would be great. Thanks.

Do not use the Pane or the Selection object to modify headers/footers
(unless absolutely necessary).

For example, the following code will modify both header (First page and
Regular) in a *one* page document:

ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage) _
.Range.Text = "First Page"

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
.Range.Text = "Second Page and on"

It works even if the document only has one page.

Not knowing what your code does, I can't really tell you how to modify it,
but try to use my code as an example to get rid of the Selection and
ActivePane stuff.


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
[email protected]
Word MVP site: http://www.word.mvps.org
 
Z

zkid

Also, don't forget that you will need to check if the current section is set
to use "Different First Page," or the code for first page will give you an
error.
 
P

Perky Penni

I thought I might make "DifferentFirstPage" with a line of code that first.
Then, I will tell it to be true when I need it to be true. Thanks.
 
Top