winapi - Why are the number of pages in a Word document different in Perl and Word VBA? -
I have a set of word documents for which I am trying to get many properties (number of pages, Author, etc.) using Win32 :: OLE in Perl:
print $ MSWord-> Document-> Open ($ name) - & gt; BuiltInDocumentProperties- & gt; {"Number of pages"} - & gt; Value "\ N"; This gives 4 pages, but the actual number of pages in the document is 9. The number of pages in the first section is 4. I want the number of total pages in the document.
If, within the word VBA, I do the following:
MsgBox ActiveDocument.BuiltInDocumentProperties ("number of pages") This displays 9. The number of pages displayed in the Properties / Statistics page is 9.
Do I have to compel the recapture? Is there any way of putting pressure on the OLE library to recalculate, or do I have to treat each section separately?
I am at XP, Word 2007, ActivePerl v5.10.0.
#! Use / usr / bin / perl strict; Use warnings; File :: spec :: functions use qw (catfile); Use Win32 :: OLE; Use Win32 :: OLE :: Conte 'Microsoft Word'; $ Win32 :: OLE :: Alert = 3; My $ word = get_word (); $ Word- & gt; {Visible} = 1; My $ Doctor = $ word- & gt; {Document} - & gt; Open (CatFile $ enV {TEMP}, 'test.doc'); $ Doctor & gt; Repaginate; My $ copies = $ doc- & gt; Biltine Document Properties; My $ x = $ property- & gt; Items (wdPropertyPages) - & gt; Valof; Print "$ x \ n"; $ Doctor & gt; Off (0); Sub get_word {my $ word; Eval {$ word = Win32 :: OLE- & gt; GetActiveObject ('Word.Application'); }; Die "$ @ \ n" if $ @; Unless (defined $ word) {$ word = Win32 :: OLE- & gt; New ('Word.Application', sub {$ _ [0] - & gt; Skip)) or die "Oh, Word can not start:", Win32 :: OLE- & gt; Last errer, "\ n"; } Return word; }