Set focus on cursor

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

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