Hi everyone,
Is there programmatic way to get out of the header footer mode ?
Thanks,
Hi everyone,
Is there programmatic way to get out of the header footer mode ?
Thanks,
A quick 'record macro' for exiting header/footer mode gives me this:
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Regards,
Aardigspook
I recently started a new job so am a bit busy and may not reply quickly. Sorry - it's not personal - I will reply eventually.
If your problem is solved, please go to 'Thread Tools' above your first post and 'Mark this Thread as Solved'.
If you use commas as your decimal separator (1,23 instead of 1.23) then please replace commas with semi-colons in your formulae.
You don't need to give me rep if I helped, but a thank-you is nice.
Do note there's probably nothing you'd need to do programmatically that requires switching to the header/footer view to begin with, so not doing so also obviates the need to exit it.
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Hi everyone,
My program needs to go through both Word::Fields and Word::Headers of Word::Document.
After I call Word::HeaderFooter::get_Range(...), I believe Word automatically goes into Header/Footer mode, and the number of pages are changed too.
I need to find a way to go back to original mode.
Word::Window::put_SeekView(...) may not be the right way, but it helps me resolving my problem for now
... ...
Word::WindowPtr pWnd = spDoc->GetActiveWindow();
Word::ViewPtr pView = pWnd->GetView();
HRESULT hr = pView->put_SeekView(Word::wdSeekPrimaryHeader);
hr = pView->put_SeekView(Word::wdSeekMainDocument);
... ...
Thanks,
Last edited by neu_stone; 10-13-2015 at 10:25 AM.
Accessing a header or footer doesn't have any affect of the number of pages in a document. You say you need to access both fields and headers & footers. That can be done without ever switching to the header/footer view. For example, the following code processes fields in the body of the document and in all headers & footers:
Please Login or Register to view this content.
Last edited by macropod; 10-13-2015 at 10:53 AM.
Hi Macropod,
I did do in the same way.
My 1-page doc has narrow margins, and there is one table occupying the whole page.
My codes is like:
... ...
Word::_DocumentPtr spDoc = nullptr;
hr = pApp->get_ActiveDocument(&spDoc);
...
Word::SectionPtr spSection = nullptr;
hr = spSections->Item(lIndex, &spSection);
ASSERT(spSection);
Word::HeadersFootersPtr spHeaders = nullptr;
hr = spSection->get_Headers(&spHeaders);
ASSERT(spHeaders);
Word::HeaderFooterPtr spPrimaryHeader = nullptr;
hr = spHeaders->Item(Word::wdHeaderFooterPrimary, &spPrimaryHeader);
ASSERT(spPrimaryHeader);
Word::RangePtr spRange = nullptr;
hr = spPrimaryHeader->get_Range(&spRange);
... ...
Then the status of my doc was changed.
Xin
before.png
after.png
When you access the header/footer area for the first time, Word automatically creates an empty paragraph for both the header and the footer. And, because the header & footer now have content, Word allocates whatever the minimum space is that you've provided for the header and footer as part of the page layout. That explains why your content, which is too large for the space allocated to the header and footer, has moved.
Hi Macropod,
Is there a way to check the empty of Header/Footer, or release the empty paragraph ?
For now, I have to call Word::View::put_SeekView(...) twice, with wdSeekPrimaryHeader or wdSeekMainDocument respectively. This helps me releasing empty paragraph.
Thanks,
Perhaps you should ask why you're accessing it if you're not putting any content there? The attachment to your previous post indicates it was still empty.
Hi Macropod,
Let's assume that my program is to perform automation test.
When test doc is opened, both header/Footer and main body will be automatically gone through for specific data.
We don't know if there is any content there in Header/Footer.
Regards,
In that case you could test the content using code like:
Such code won't affect anything.Please Login or Register to view this content.
Hi Macropod,
Your method works.
I made small changes to your codes, because .StoryRanges(wdPrimaryHeaderStory) will throw an error in my case.
Below is my codes in C++:
...
HRESULT hr;
///. storyRanges :
///. A collection of Range objects that represent stories in a document.
Word::StoryRangesPtr pStoryRanges = nullptr;
hr = spDoc->get_StoryRanges(&pStoryRanges);
ASSERT(pStoryRanges);
///. Use StoryRanges(Index), where Index is a WdStoryType constant,
///. to return a single story as a Range object.
Word::RangePtr pPrimaryHeaderRange = nullptr;
hr = pStoryRanges->raw_Item(Word::wdPrimaryHeaderStory, &pPrimaryHeaderRange);
if(pPrimaryHeaderRange)
{
...
}
... ...
Thanks,
Hi Macropot,
After knowing the count of StoryRanges, for example 5, how to get Range object by index number (not the specified story type) ?
Thanks,
There is no such thing as a count of story ranges. Word has 17 predefined story ranges:
WdStoryType Enumeration
Value Name
1 wdMainTextStory
2 wdFootnotesStory
3 wdEndnotesStory
4 wdCommentsStory
5 wdTextFrameStory
6 wdEvenPagesHeaderStory
7 wdPrimaryHeaderStory
8 wdEvenPagesFooterStory
9 wdPrimaryFooterStory
10 wdFirstPageHeaderStory
11 wdFirstPageFooterStory
12 wdFootnoteSeparatorStory
13 wdFootnoteContinuationSeparatorStory
14 wdFootnoteContinuationNoticeStory
15 wdEndnoteSeparatorStory
16 wdEndnoteContinuationSeparatorStory
17 wdEndnoteContinuationNoticeStory
If you want to get the nth field in the Primary Header Story, you would have to reference the nth field in that story. For example:
Activedocument.StoryRanges(wdPrimaryHeaderStory).Fields(5)
to reference the 5th field in the Primary Header Story. This gets complicated when your document has multiple Sections with headers that may or may not be linked to those of the preceding Section(s).
Hi Macropod,
Thanks for your help.
Regards,
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks