To create a LibreOffice Writer macro that selects "Track Changes" > "Compare Document" using the built-in/calculated path file compare, follow the steps below:
-
Open LibreOffice Writer and press
Alt + F11to open the Basic IDE. -
Click on
Insert>Moduleto create a new module. -
Paste the following code into the module:
Sub CompareDocuments()
Dim sPath1 As String
Dim sPath2 As String
Dim sPathCompare As String
Dim oDoc As Object
' Set the paths for the first and second documents
sPath1 = ThisComponent.Path
sPath2 = "path/to/second/document.odt"
' Calculate the path for the compare document
sPathCompare = Left(sPath1, InStrRev(sPath1, "\") + 1) & "Compare" & Right(sPath1, Len(sPath1) - InStrRev(sPath1, "\") - 5) & "_" & Mid(sPath2, InStrRev(sPath2, "\") + 1) & "_compare.odt"
' Open the first document
Set oDoc = ThisComponent.OpenFromURL(sPath1)
' Compare the documents
oDoc.Tools.ExecuteCommandLine "TrackChangesCompareDocument " & sPath2 & " " & sPathCompare
' Close the document
oDoc.Close SaveChanges:=False
End Sub
-
Replace
"path/to/second/document.odt"with the path to the second document you want to compare. -
Save the module and close the Basic IDE.
-
To run the macro, press
Alt + F8, select the macro, and clickRun.
This macro will open the first document, compare it with the second document, and save the compare result as a new document in the same folder as the first document, with the name "Compare_first_document_second_document_compare.odt".
Note that the macro uses the TrackChangesCompareDocument command, which is only available when "Track Changes" is enabled. Also, the macro does not check if the second document exists, so make sure it is available at the specified path before running the macro.
To avoid mentioning multipage articles, you can split the macro execution into multiple subroutines, each handling a specific part of the process. However, this might complicate the code and make it less readable.