How To Get the Range of a Page Using Word Automati

2019-07-16 18:05发布

问题:

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.

回答1:

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


回答2:

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



回答3:

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."