views:

475

answers:

3

How do you find the range of page n in Microsoft Word using office automation? There appears to be no getPageRange(n) function and it is unclear how they are divided.

A: 

Apologies if I don't have the right context for your question, but from looking at the Office Development docs it seems as though you have to create Range objects that contain what you want. The "Range Object" section of this page says: "The Range object represents a contiguous area in a document, and is defined by a starting character position and an ending character position. You are not limited to a single Range object. You can define multiple Range objects in the same document... [A Range] is not saved with a document and exists only while the code is running."

aem
This is true, but it is not clear to me how to easily acquire a range for the nth page.
Steve
Yeah, they don't make it especially easy to figure that out from the docs. :(http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.page.aspx has info on the Page object. I still haven't put it all together, but I suspect the Document object (http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.document.aspx) will have a Pages member which gives you an array of the pages, and from that maybe you'll be able to get a Range object.
aem
nah no pages member. you have stories, paragraphs, sentances and ranges (generic).
Anonymous Type
A: 

You can use the Matlab OfficeDoc utility for reading/writing Word contents from Matlab: http://www.mathworks.com/matlabcentral/fileexchange/15192-officedoc-readwriteformat-ms-office-docs-xlsdocppt

Yair Altman
+1  A: 

This is how you do it from VBA, should be fairly trivial to convert to Matlab COM calls.

Public Sub DemoPerPageText()

    Dim i As Integer
    Dim totalPages As Integer
    Dim bmRange As Range

    totalPages = Selection.Information(wdNumberOfPagesInDocument)

    For i = 1 To totalPages
      Set bmRange = ActiveDocument.Bookmarks("\Page").Range
      Debug.Print CStr(i) & " : " & bmRange.Text & vbCrLf
    Next i

End Sub
Anonymous Type