2011-07-15 45 views
2

我試圖創建一個宏,它將更改並替換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」替換當前選中的文本?

感謝

回答

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 
+0

甚至simplier: 'oVC.setString(processSelection(oVC.String))' – Pierre