Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2004

Tip: Looking for answers? Try searching our database.

Word header height and view problems.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
abc - 29 Mar 2004 11:53 GMT
I have a word document with different first page header.  I would like to
print the height of the two headers (first page and primary headers).
My code prints the height of the first header and then tries to print the
second header's height.  To do that, I select the first header and switch to
printview and then find the height.  I then goto the normal view and then
select the primary header and switch to print view to find the height once
again.  THe problem is that when I switch from normal to print view in the
second case, the cursor hops into the first page header.  Therefore always
returning me the first page header height only.

Please try the following code with two headers of different heights.

PS - If i don't switch to normal view wdVerticalPositionRelativeToPage
always returns me -1.  Therefore, I have to keep switching from normal to
print and get the results.

My code that does this is as follows -

set sec = ActiveDocument.Sections(1)
ActiveWindow.View.Type = wdNormalView
Set hdf = sec.Headers(wdHeaderFooterFirstPage)
print hdf.Range.Select()
ActiveWindow.View.Type = wdPrintView
ActiveWindow.Selection.EndKey(wdStory)
print ActiveWindow.Selection.Information(wdVerticalPositionRelativeToPage)

ActiveWindow.View.Type = wdNormalView
Set hdf2 = sec.Headers(wdHeaderFooterPrimary)
print hdf2.Range.Select()
ActiveWindow.View.Type = wdPrintView
ActiveWindow.Selection.EndKey(wdStory)
print ActiveWindow.Selection.Information(wdVerticalPositionRelativeToPage)

I have tried many combinations and I am writing this mail as a last resort.
All I am trying to do is collect heights of all headers.  Once the above
code works , I plan to collect the same for all sections.

Thanks a ton in advance.
Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS - 29 Mar 2004 22:47 GMT
This works:

Dim myrange As Range
ActiveWindow.View = wdPrintView
Set myrange =
ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
myrange.Collapse wdCollapseEnd
MsgBox myrange.Information(wdVerticalPositionRelativeToPage)
Set myrange =
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range = myrange
Set myrange =
ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
myrange.Collapse wdCollapseEnd
MsgBox myrange.Information(wdVerticalPositionRelativeToPage)
ActiveDocument.Undo

Signature

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested.  Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP

>I have a word document with different first page header.  I would like to
> print the height of the two headers (first page and primary headers).
[quoted text clipped - 36 lines]
>
> Thanks a ton in advance.
abc - 30 Mar 2004 06:51 GMT
Thanks for the solution.  However, the solution adds unnecessary things to
the undo stack.  Is there a cleaner way to do something similar?
TIA

> This works:
>
> Dim myrange As Range
> ActiveWindow.View = wdPrintView
> Set myrange =
> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS - 30 Mar 2004 10:30 GMT
I would not have thought that was such a great problem.

Add an

ActiveDocument.UndoClear

at the end

Signature

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested.  Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP

> Thanks for the solution.  However, the solution adds unnecessary things to
> the undo stack.  Is there a cleaner way to do something similar?
[quoted text clipped - 6 lines]
>> Set myrange =
>> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
abc - 31 Mar 2004 06:00 GMT
Thanks a lot.  I was just being a bit choosy :-)  Nevertheless, your code
works and mine wasn't working at all.

The reason I was not trying to change anything in the undo stack was that my
code would work on an user document and I would not want the user to see
unnecessary undo commands on the undo stack.  Additionally, I would also not
like to clear his/her undo stack.  Anyways, I will try working with this
limitation for some time.

Thanks a lot.

> I would not have thought that was such a great problem.
>
[quoted text clipped - 14 lines]
> >> Set myrange =
> >> ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.