Search code examples
macrosreplaceselectionopenoffice.orgopenoffice-writer

OpenOffice Writer. Macro : replacing the selected text


I'm trying to create a macro that would change and replace the current selected text in OpenOffice Writer.

So far my macro looks like this:

sub myReplaceSelection
Dim oDoc
Dim oVC
Dim R As String

oDoc = ThisComponent
oVC = oDoc.CurrentController.getViewCursor
If Len(oVC.String) > 0 Then
   R = processSelection(oVC.String)
   'replace the selection:
   'which function should I call here ? <------------------
   '
EndIf
End sub

Function processSelection( s As String) As String
 '... ok , this part works fine
End Function

How can I replace the current selected text with my String 'R' ?

Thanks


Solution

  • OK got it:

    If Len(oVC.String) > 0 Then
      oVC = oDoc.CurrentController.getViewCursor
      If Len(oVC.String) > 0 Then
      Dim document   as object
      dim args1(0) as new com.sun.star.beans.PropertyValue
      args1(0).Name = "Text"
      args1(0).Value = processSelection(oVC.String)
      document = oDoc.CurrentController.Frame
      dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
    EndIf