Determining header and footer height

B

Bob in SD

Within a VBA script program (or VB program), I would like to know the
distance from the top edge of the page to the bottom of the header. Also
need to know the distance from the bottom edge of the page to the top of the
footer.

PageSetup.HeaderDistance and PageSetup.FooterDistance seem to provide the
distance of the top of the header to the top edge of the page and the
distance from the bottom of the footer to the bottom of the page. Not quite
what I need. Any recommendations?

Background: The header content of the document is dynamic. Am writing a VB
program which pastes a picture onto the page. Will adjust the size of the
picture based on the size of the header and footer. (Once I know how big the
header and footer are.) Manually, one can just look at the ruler on the
screen, but how to do this within the program?
 
C

Chad DeMeyer

Something like this:

Set oHdr = ActiveDocument.Sections(1).Headers(1).Range
lTop =
oHdr.Paragraphs(oHdr.Paragraphs.Count).Range.Information(wdVerticalPositionR
elativeToPage)
lBottom =
ActiveDocument.Sections(1).Footers(1).Range.Paragraphs(1).Range.Information(
wdVerticalPositionRelativeToPage)
lSpaceAvailable = lBottom - lTop - 10 'for extra padding of 5 points
above and below
lInInches = PointsToInches(lSpaceAvailable)

Regards,
Chad
 

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