Ask Your Question

Revision history [back]

According to the OOo Developer's Guide, p. 828, "Certain information about the current layout, such as the number of lines and page number must be retrieved at the view cursor." So, it would seem that there's no way around using the visible cursor.

You might try moving the view cursor to get the page number and then moving it back to it's previous location. Here's a possible approach, based on Jim's example code. Note that the code hasn't been tested, and I don't know if such an approach would cause some unsightly flicker of the display.

Sub PageOfBookmark
    oDoc = ThisComponent
    oVC = oDoc.getCurrentController().getViewCursor()

    REM Save view cursor location
    oText = ThisComponent.Text
    oTextCursor = oText.createTextCursorByRange(oVC)

    oBookmark = oDoc.getBookmarks().getByName("Bookmark 1")
    oVC.gotoRange(oBookmark.getAnchor(), False)

    REM Grab page number and then return view cursor to previous location
    pg = oVC.getPage()
    oVC.gotoRange(oTextCursor, False)

    MsgBox "Bookmark is on page " & pg
End Sub