Page Count problem using BuiltinDocumentProperties 
Author Message
 Page Count problem using BuiltinDocumentProperties

Hi,

I have written a function which should return the number of page of a
document like the code below:

Public Function intWordPageCount(ByRef strFileName As String) As Integer

    'MS Word and Document Objects
    Dim wrd     As New Word.Application
    Dim myDoc   As New Word.Document

    'Open MS Word Document
    Set myDoc = wrd.Documents.Open(strFileName)

    'Pause 10 sec, reason : allow MS Word to finish loading whole document
    Sleep 10000

    'Return total number of pages of document
    intWordPageCount = myDoc.BuiltinDocumentProperties(wdPropertyPages)

    'Close Document Object
    myDoc.Close

    'Close MS Word
    wrd.Quit wdDoNotSaveChanges

End Function

Anyone can help me with this? If I take out "Sleep 10000",
myDoc.BuiltinDocumentProperties(wdPropertyPages) doesnt return the correct
number of pages sometimes. For example, if a document has 200 pages, it may
come out to return 140, or sometimes 199, instead of 200. To me, it seems it
takes some time for MS word to think and get the number of pages. After i
put "Sleep 10000", 99% I got the correct number of pages. However, this will
take very long time to process as I need to read 200 to 300 files and the
number of pages from each files. Please let me know if there is another
better solution for this.

Thanks.



Sun, 30 Jan 2005 15:37:08 GMT  
 Page Count problem using BuiltinDocumentProperties
Hi Michael,

Don't recreate the wheel. Something much easier has already been done. See
"Using VBA, how can I get access to the Document Properties of a Word file
without opening the document?" at
http://www.mvps.org/word/FAQs/MacrosVBA/DSOFile.htm

I tried the template method; worked like a charm.

HTH


Quote:
> Hi,

> I have written a function which should return the number of page of a
> document like the code below:

> Public Function intWordPageCount(ByRef strFileName As String) As Integer

>     'MS Word and Document Objects
>     Dim wrd     As New Word.Application
>     Dim myDoc   As New Word.Document

>     'Open MS Word Document
>     Set myDoc = wrd.Documents.Open(strFileName)

>     'Pause 10 sec, reason : allow MS Word to finish loading whole document
>     Sleep 10000

>     'Return total number of pages of document
>     intWordPageCount = myDoc.BuiltinDocumentProperties(wdPropertyPages)

>     'Close Document Object
>     myDoc.Close

>     'Close MS Word
>     wrd.Quit wdDoNotSaveChanges

> End Function

> Anyone can help me with this? If I take out "Sleep 10000",
> myDoc.BuiltinDocumentProperties(wdPropertyPages) doesnt return the correct
> number of pages sometimes. For example, if a document has 200 pages, it
may
> come out to return 140, or sometimes 199, instead of 200. To me, it seems
it
> takes some time for MS word to think and get the number of pages. After i
> put "Sleep 10000", 99% I got the correct number of pages. However, this
will
> take very long time to process as I need to read 200 to 300 files and the
> number of pages from each files. Please let me know if there is another
> better solution for this.

> Thanks.



Sun, 30 Jan 2005 20:26:15 GMT  
 Page Count problem using BuiltinDocumentProperties
Hi Michael,

After playing with it for a bit, I noticed that it sometimes returns the
wrong page count. If you experience the same thing, then you're probably
using Word 2000, and apparently there is no work around. Have a look at the
article "WD2000: Word Document Statistics Different Viewing from Windows
Explorer" at http://support.microsoft.com/default.aspx?scid=kb;en-us;Q244839

HTH


Quote:
> Hi,

> I have written a function which should return the number of page of a
> document like the code below:

> Public Function intWordPageCount(ByRef strFileName As String) As Integer

>     'MS Word and Document Objects
>     Dim wrd     As New Word.Application
>     Dim myDoc   As New Word.Document

>     'Open MS Word Document
>     Set myDoc = wrd.Documents.Open(strFileName)

>     'Pause 10 sec, reason : allow MS Word to finish loading whole document
>     Sleep 10000

>     'Return total number of pages of document
>     intWordPageCount = myDoc.BuiltinDocumentProperties(wdPropertyPages)

>     'Close Document Object
>     myDoc.Close

>     'Close MS Word
>     wrd.Quit wdDoNotSaveChanges

> End Function

> Anyone can help me with this? If I take out "Sleep 10000",
> myDoc.BuiltinDocumentProperties(wdPropertyPages) doesnt return the correct
> number of pages sometimes. For example, if a document has 200 pages, it
may
> come out to return 140, or sometimes 199, instead of 200. To me, it seems
it
> takes some time for MS word to think and get the number of pages. After i
> put "Sleep 10000", 99% I got the correct number of pages. However, this
will
> take very long time to process as I need to read 200 to 300 files and the
> number of pages from each files. Please let me know if there is another
> better solution for this.

> Thanks.



Sun, 30 Jan 2005 22:09:45 GMT  
 Page Count problem using BuiltinDocumentProperties

try a DoEvents to let background processes get some quality time in
:-)


that went like this:

Quote:
>Hi,

>I have written a function which should return the number of page of a
>document like the code below:

>Public Function intWordPageCount(ByRef strFileName As String) As Integer

>    'MS Word and Document Objects
>    Dim wrd     As New Word.Application
>    Dim myDoc   As New Word.Document

>    'Open MS Word Document
>    Set myDoc = wrd.Documents.Open(strFileName)

>    'Pause 10 sec, reason : allow MS Word to finish loading whole document
>    Sleep 10000

>    'Return total number of pages of document
>    intWordPageCount = myDoc.BuiltinDocumentProperties(wdPropertyPages)

>    'Close Document Object
>    myDoc.Close

>    'Close MS Word
>    wrd.Quit wdDoNotSaveChanges

>End Function

>Anyone can help me with this? If I take out "Sleep 10000",
>myDoc.BuiltinDocumentProperties(wdPropertyPages) doesnt return the correct
>number of pages sometimes. For example, if a document has 200 pages, it may
>come out to return 140, or sometimes 199, instead of 200. To me, it seems it
>takes some time for MS word to think and get the number of pages. After i
>put "Sleep 10000", 99% I got the correct number of pages. However, this will
>take very long time to process as I need to read 200 to 300 files and the
>number of pages from each files. Please let me know if there is another
>better solution for this.

>Thanks.

Steve Hudson -- Word Heretic, Sydney, Australia
{*filter*} teacher, trainer, tutor, writer, developer

Word MVP FAQs: http://www.*-*-*.com/
You agree by writing to me personally that any material can be reused publicly unless you explicitly disclaim it. (For List and blog use.)


Mon, 31 Jan 2005 09:43:00 GMT  
 Page Count problem using BuiltinDocumentProperties
Thanks Dave,

Do you think I can solve this problem if I use Word 97 instead?

Michael

Quote:
> Hi Michael,

> After playing with it for a bit, I noticed that it sometimes returns the
> wrong page count. If you experience the same thing, then you're probably
> using Word 2000, and apparently there is no work around. Have a look at
the
> article "WD2000: Word Document Statistics Different Viewing from Windows
> Explorer" at

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q244839
Quote:

> HTH



> > Hi,

> > I have written a function which should return the number of page of a
> > document like the code below:

> > Public Function intWordPageCount(ByRef strFileName As String) As Integer

> >     'MS Word and Document Objects
> >     Dim wrd     As New Word.Application
> >     Dim myDoc   As New Word.Document

> >     'Open MS Word Document
> >     Set myDoc = wrd.Documents.Open(strFileName)

> >     'Pause 10 sec, reason : allow MS Word to finish loading whole
document
> >     Sleep 10000

> >     'Return total number of pages of document
> >     intWordPageCount = myDoc.BuiltinDocumentProperties(wdPropertyPages)

> >     'Close Document Object
> >     myDoc.Close

> >     'Close MS Word
> >     wrd.Quit wdDoNotSaveChanges

> > End Function

> > Anyone can help me with this? If I take out "Sleep 10000",
> > myDoc.BuiltinDocumentProperties(wdPropertyPages) doesnt return the
correct
> > number of pages sometimes. For example, if a document has 200 pages, it
> may
> > come out to return 140, or sometimes 199, instead of 200. To me, it
seems
> it
> > takes some time for MS word to think and get the number of pages. After
i
> > put "Sleep 10000", 99% I got the correct number of pages. However, this
> will
> > take very long time to process as I need to read 200 to 300 files and
the
> > number of pages from each files. Please let me know if there is another
> > better solution for this.

> > Thanks.



Mon, 31 Jan 2005 09:50:20 GMT  
 Page Count problem using BuiltinDocumentProperties
Hi Michael,

Instead of  "Sleep 10000", I think it would be better to force a
repagination of the document:
  ActiveDocument.Repaginate

Hope that solves the problem,
Klaus



Mon, 31 Jan 2005 09:50:22 GMT  
 Page Count problem using BuiltinDocumentProperties
Klaus,

This really solve my problem. I really appreciate to who reply to my post.
Thanks.

Michael

Quote:
> Hi Michael,

> Instead of  "Sleep 10000", I think it would be better to force a
> repagination of the document:
>   ActiveDocument.Repaginate

> Hope that solves the problem,
> Klaus



Mon, 31 Jan 2005 15:53:31 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. referencing BuiltInDocumentProperties causes a word count

2. Page header and BuiltInDocumentProperties

3. Problems with page count

4. ASP Page's DLL's Use Count Not Going To Zero (or similar problem)

5. Total Page Count Problem when running executable

6. CRYSTAL REPORTS 6 (32bit) - Total Page Count Problem

7. Total Page Count Display Problem

8. Excel:Count pages & print page to printfile

9. Excel:Count pages & print page to printfile

10. Problem counting record values using formulas

11. How do I Use the BuiltInDocumentProperties

12. BuiltInDocumentProperties

 

 
Powered by phpBB® Forum Software