Hi all,
I try to write a macro that accepts all changes and saves a document via the command line in headless mode. Starting opening soffice in headless and running the macro works! I have to add, that I am totally new to macros in libreoffice.
But when I try to call the dispatcher it throws an error. I read, that the dispatcher only works with UI.
What possibilities do I have to call the uno function to accept all changes?
Sub AcceptChangesAndSave(sSourcePath As String)
Dim sPath As String
Dim oDoc As Object
Dim loadComponentProperties(0) As New com.sun.star.beans.PropertyValue
Rem Prevent screen flashing
loadComponentProperties(0).Name= "Hidden"
loadComponentProperties(0).Value= True
Rem Load document.
GlobalScope.BasicLibraries.LoadLibrary("Tools")
sPath = ConvertToURL(sSourcePath)
Rem If a file exists:
If FileExists(sPath) Then
Rem Open Document:
oDoc = OpenDocument(sPath,loadComponentProperties)
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
REM dispatcher.executeDispatch(oDoc, ".uno:AcceptAllTrackedChanges", "", 0, Array())
Rem Save:
oDoc.store()
Rem and close
oDoc.close(True)
EndIf
end sub
The command that throws an error is:
dispatcher.executeDispatch(oDoc, “.uno:AcceptAllTrackedChanges”, “”, 0, Array())
The error is:
Thanks for any tips!
DomCa