OpenOffice Writer。宏:替换所选文本

时间:2011-07-15 14:58:30

标签: macros replace selection openoffice.org openoffice-writer

我正在尝试创建一个可以更改和替换OpenOffice Writer中当前所选文本的宏。

到目前为止,我的宏看起来像这样:

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

如何用字符串'R'替换当前选定的文本?

由于

1 个答案:

答案 0 :(得分:0)

确定了:

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