Reputation: 660
I have a Word document and want to get the page number for any arbitrary paragraph within the document. I realise that paragraphs can span pages, so I actually need to ask about the start (or end) of the paragraph. Something like this pseudocode:
set the_page_number to page number of character 1 of paragraph 1 of my_document
I haven't been able to figure out how you link a range object with any kind of information about its rendering and am officially baffled.
Does anyone know the proper way?
Upvotes: 1
Views: 508
Reputation: 660
I just found this question about dealing with this in C#: How do I find the page number for a Word Paragraph?
Poking around in the answer to that I found reference to range.get_Information(Word.WdInformation.wdActiveEndPageNumber)
It turns out there's a get range information
command in the applescript dictionary, so you can do this:
set the_range to text object of character 1 of paragraph 123 of the_document
set page_number to get range information the_range information type active end adjusted page number
That'll get the page number that would be printed (e.g. if you'd set the document to start at page 42, this will produce the number you expect). Or, you can get the number without adjustment, i.e. your document page numbering is set to start at 42, but you want the page number as if numbering started at 1.
set the_range to text object of character 1 of paragraph 456 of the_document
set page_number to get range information the_range information type active end page number
Phew.
Upvotes: 3