Ask Your Question

Set focus on cursor

asked 2019-02-24 00:09:53 +0100

Joe-- gravatar image

I'm writing a simple macro to search for text. The searching works, but the page does not scroll to the found text. The cursor apparently is being moved, just not focused. After the macro runs, if I hit an arrow key, the page immediately scrolls to the found text.

This is my code:

sub FindIt
    dim oDoc as object
    dim oSearch as object
    dim oResult as object
    dim oCursor as object
    Dim answer

    oDoc = thiscomponent
    oSearch = oDoc.createSearchDescriptor()

    with oSearch
        .SearchString = "searchtest"
        .SearchRegularExpression = True
        .SearchCaseSensitive = true
    end with

    oResult = oDoc.findFirst(oSearch)

    While Not IsNull(oResult)
        oCursor = oDoc.CurrentController.ViewCursor
        oCursor.gotoRange(oResult, false)
        answer = MsgBox("Found: " & oResult.String ,4,"Title")

        oResult = oDoc.FindNext(oResult,oSearch)
end sub
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-04-13 16:59:20 +0100

Joe-- gravatar image

Found the solution to my problem. The macro has to be launched from the Writer screen (not the macro editor screen).

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-02-24 00:09:53 +0100

Seen: 134 times

Last updated: Apr 13 '19