headerfooter alignment relative to page size, orientation

S

sugarboyrosnerd

Software: Word 2000

I have a template that uses header/footer protection code located at:
http://www.word.mvps.org/FAQs/Customization/ProtectWord2000PlusHeader.htm
(link graciously provided by Doug Robbins)
This protection works very well, but has spawned another issue.

PROBLEM:
If the user changes the page size or page orientation in a section, the
header and footer content no longer aligns with the new header and footer
margins. Since the header/footer is protected, the user can't adjust the
header/footer content alignment.

DETAILS:
This template needs to accept only the following page layout specfications.
Letter (8.5x11) page size – portrait orientation
Letter (8.5x11) page size – landscape orientation
Ledger (11X17) page size – portrait orientation
Ledger (11X17) page size – landscape orientation

MY SOLUTION THUS FAR:
I have created six styles to accomodate all acceptable page sizes and
orientations listed above. They are:
1. Header (Letter – portrait)
2. Header 11 (Letter – landscape; Ledger – portrait)
3. Header 17 (Ledger – landscape)
4. Footer (Letter – portrait)
5. Footer 11 (Letter – landscape; Ledger – portrait)
6. Footer 17 (Ledger – landscape)

Header and footer content contains docvariable fields that are updated by
userform values. Ideally, I would like to programatically align all header
and footer content based on the page size and page orientation, after the
userform that populates headers and footers is executed.

Can this be accomplished without the creation of the six styles listed above?
Is there a better way?
Am I making sense?

best wishes from Western Canada,
sugarboyrosnerd
 
C

Colleen M

For items that must be left, centre or right aligned, you can place the
contents in a text box, and set the alignment of the text box to left, centre
or right. When you change the page size or orientation, the text boxes will
automatically realign themselves.
 
S

sugarboyrosnerd

Thank you for this Colleen. Your suggestion does work. However ...

I was hoping to avoid using text boxes because my code does not update
docvariable fields if I place them into text boxes. Currently, my
docvariables update seamlessly (without using text boxes). Putting
docvariable fields into text boxes within headers and footers to address
alignment issues seems to be a kluge because it requires me to rewrite code
to update the docvariable fields.

Is there a way to programmatically detect the margins of my headers and
footers and adjust headerfooter docvariable field alignment without using
text boxes?

best wishes from Western Canada,
sugarboyrosnerd
 
C

Colleen M

You're right about text boxes. Instead, use Frames. They can be
left/centre/right aligned, and fields will update inside Frames.
 
D

Derek

Thanks for your speedy response Colleen.

Unfortunately, frames will not work for this project. Users that use the
templates I'm creating are unfamiliar with frames (read: afraid of frames).
In addition, I get a Winword.exe error when I try to save my template with a
frame.

Hmmmm ...

Perhaps we can go back around the board.

I'll try using text boxes. However, I need to know if it is possible to
update docvariable fields that are located in text boxes within
headers/footers.

Is this possible? If not, I'm at a loss.

Currently, I use the following code to update docvariable fields in headers.
Can this be modified to update docvariable fields in text boxes within
headers/footers?

Sub UpdateHeaderFields()
Dim hRange As Word.Range
Set hRange = ActiveDocument.StoryRanges(wdPrimaryHeaderStory)
Do
hRange.Fields.Update
Set hRange = hRange.NextStoryRange
Loop Until hRange Is Nothing
End Sub
 
C

Colleen M

Hi Derek,
The code works for me to update text boxes.

Dim hRange As Word.Range
Set hRange = ActiveDocument.StoryRanges(wdPrimaryHeaderStory)
hRange.Select
Selection.Fields.Update

But for some reason I haven't dug into, it also changes my document view
from print layout view to normal, with header contents displayed at the
bottom of the page. If you can figure that one out, then hopefully your
problem will be solved.
 
C

Colleen M

Okay, I had to try to figure it out. The code below works for me, and doesn't
change the print preview display.

ActiveWindow.ActivePane.View.SeekView = wdSeekPrimaryHeader
Selection.WholeStory
Selection.Fields.Update
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
 
C

Colleen M

Hi Cindy,

This works for Frames, but unless I select everything first, text boxes
don't get updated.

I use frames all the time, but Derek was having trouble using frames, so
wanted to stick with text boxes.
 
D

Derek

Hi Colleen.
Unfortunately , this code does not work in my document.
Fortunately, however, I've been closely following another similar thread
between Brent and Jezebel. Jezebel provided Brent (and therefore me) with the
following code. It works!
....
Sub Giddeeup()
Dim pRange As Word.Range
Dim pShape As Word.Shape

On Error Resume Next
For Each pRange In ActiveDocument.StoryRanges
Do
pRange.Fields.Update
For Each pShape In pRange.ShapeRange
pShape.TextFrame.TextRange.Fields.Update
Next
Set pRange = pRange.NextStoryRange
Loop Until pRange Is Nothing
Next
on error goto 0

'Jezebel's note: The 'on error resume next' is needed because the ShapeRange
reference throws an error for some storyranges.

This solution is going to give me king-like status at work. Thank you so
much for your time. I really can't thank you enough ... and you too Jezebel.

best wishes from Western Canada,
/Derek
 

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