Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 199313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:00:45+00:00 2026-05-11T17:00:45+00:00

I have a (set of) Word document(s) for which I’m trying to get various

  • 0

I have a (set of) Word document(s) for which I’m trying to get various properties (number of pages, author, etc) using Win32::OLE in Perl:

print $MSWord->Documents->Open($name)->
BuiltInDocumentProperties->{"Number of pages"}->value . " \n";

This returns 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 total number of pages in the document.

If, within 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 force a recalculate? Is there some way to ask the OLE library to force a recalculate or do I have to treat every section separately?

I’m on XP, Word 2007, ActivePerl v5.10.0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:00:46+00:00Added an answer on May 11, 2026 at 5:00 pm
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use File::Spec::Functions qw( catfile );
    
    use Win32::OLE;
    use Win32::OLE::Const 'Microsoft Word';
    $Win32::OLE::Warn = 3;
    
    my $word = get_word();
    $word->{Visible} = 1;
    
    my $doc = $word->{Documents}->Open(catfile $ENV{TEMP}, 'test.doc');
    $doc->Repaginate;
    
    my $props = $doc->BuiltInDocumentProperties;
    my $x = $props->Item(wdPropertyPages)->valof;
    print "$x\n";
    
    $doc->Close(0);
    
    sub get_word {
        my $word;
        eval {
            $word = Win32::OLE->GetActiveObject('Word.Application');
        };
    
        die "$@\n" if $@;
    
        unless(defined $word) {
            $word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit })
                or die "Oops, cannot start Word: ", 
                       Win32::OLE->LastError, "\n";
        }
        return $word;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of Word documents which I want to publish using a
Making a word document of our network set-up. We have about 7 servers and
I have one command line application which print word document. As per new requirement,
I have a Word document with two embedded Excel files (added using Insert ->
I have a Word document that contains about 4000 form fields which I have
I have some VSTO code which generates a Word 2003 document by copying and
I have working code that opens up a word document programmatically using vbscript, makes
I have an application which creates and opens a document in Word. The user
Using WiX (Windows Installer XML) I have created an MSI installer which installs Word
I have set up upload_max_filesize and post_max_size to 32Mb in php.ini. I am using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.