This can be done.
The text of the macro can be something like this:
Option Explicit
Sub ReplacePlaceholders(Optional pairDelimiter As String, _
Optional partDelimiter As String, _
Optional task As String)
Const TAG_OPEN = "["
Const TAG_CLOSE = "]"
Dim oReplaceDescriptor As Variant
Dim aTasks As Variant
Dim aPair As Variant
Dim i As Long, count As Long
If Not IsMissing(aTasks) Then
aTasks = Split(task, partDelimiter)
oReplaceDescriptor = ThisComponent.createReplaceDescriptor()
count = 0
For i = LBound(aTasks) To UBound(aTasks)
aPair = Split(aTasks(i), pairDelimiter)
If UBound(aPair) = 1 Then
oReplaceDescriptor.setSearchString(TAG_OPEN & aPair(0) & TAG_CLOSE)
oReplaceDescriptor.setReplaceString(aPair(1))
count = count + ThisComponent.replaceAll(oReplaceDescriptor)
EndIf
Next i
If count = 0 Then
MsgBox("No replacement tags found", MB_ICONEXCLAMATION, "Parameters may be incorrect")
Else
MsgBox("Replaced " & count & " tags", MB_ICONINFORMATION, "Done")
EndIf
EndIf
End Sub
Place it in My Macros in the Standard library in a separate module (e.g. rplcOnOpen)
Insert placeholders (tags) in the necessary places in the document, mark them, for example, with square brackets.
Command which will done the job will be
"C:\Program Files\LibreOffice\program\soffice.exe" C:\Tests\Test_doc.odt "macro:///Standard.rplcOnOpen.ReplacePlaceholders(;,|,Name;Mad Max|Date;2022-01-01)"
The first part is the path to the LibreOffice executable file
The next part is the path to the document being processed - Test_doc.odt
The hardest to write part of the command is the third. Here are keyword macro:///
, then Library.Module.Macro
and in parentheses parameters for the macro.