Retrieve page count in MS Word without COM? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Retrieve page count in MS Word without COM?

Post by Krd » 06 Feb 2023, 07:07

Hey!

I have a Word doc which I don't know the page count beforehand.

I have to open the doc to count the page count manually.

The doc is always either 2 or 3 pages in total.

I tried to look for common words to search for and use RegEx, but that was not working.

If the doc is in 2 pages it is almost full of words, about 350 +- words.
If the doc is in 3 pages, the page nb 2 is about 4 -6 words. The whole doc is again about 350 +- words and page 1 and 3 each containing almost half of the words.

if the doc is in 3 pages the page would contain same words 4-6 in totalt:
A city
A park in mars
or
A park in Mars

Rest is empty space until page 3.

But the problem is that these words would be in the last page of Word doc whenever it is 2 pages too.

There must be away to catch page count without COM. I think must of RegEx pros to help me here.

What if something like this could help:

Code: Select all

Clipboard := ""
Send, {Ctrl Down} a {Ctrl Up}
Sleep, 1000
Send, {Ctrl Down} c {Ctrl Up}
ClipWait
MyString := Clipboard
;Regexmatch (MyString xxx, Pagecount)
Msgbox, % Pagecount
return

I would appreciate if anyone could take a look at this when you have time :)
Other methods than COM are also welcomed? Maybe MS have a hiden way to count page numbers? Google din't make it easy for me :D


Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Retrieve page count in MS Word without COM?

Post by Krd » 06 Feb 2023, 08:36

No COM pls :D

As in this case it would never activate.

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Retrieve page count in MS Word without COM?  Topic is solved

Post by Krd » 06 Feb 2023, 08:37

It worked for now by searching for certain words in doc. will see how far it goes.

User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

Re: Retrieve page count in MS Word without COM?

Post by boiler » 06 Feb 2023, 08:49

FYI — regarding your proposed code where you have a couple lines similar to this:
Krd wrote:

Code: Select all

Send, {Ctrl Down} a {Ctrl Up}
…when you put spaces around the letter a like you did, you are actually sending Ctrl+Space, Ctrl+A, followed by another Ctrl+Space.

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Retrieve page count in MS Word without COM?

Post by Krd » 06 Feb 2023, 09:17

@boiler

OMG.

And I am using it in my scripts many places...


Thank you for making me aware of that!

Post Reply

Return to “Ask for Help (v1)”