I've been asked to do something at work, and being that I'm running Ubuntu and not Windows, I have Libre Office (LO Writer is the equivalent of Word). - The task is to automate some contracts, where the document stays 90% the same except for a few variables that change from doc to doc.
First of all - Basic is a nightmare, and generally this whole Macro writing process is also pretty awful.
Now to the "code" - I keep getting some error about BASIC error: Argument is not optional
and all I'm trying to do is pass two arrays to another function:
Function test ( ByVal changeFrom() As String ,ByVal changeTo() As String )
Dim I As Long
Dim Doc As Object
Dim Replace As Object
Doc = ThisComponent
Replace = Doc.createReplaceDescriptor
For I = 0 To 2
Replace.SearchString = changeFrom(I) //Error is here
Replace.ReplaceString = changeTo(I)
Doc.replaceAll(Replace)
Next I
End Function
REM ***** BASIC *****
Sub main
Dim changeFrom(3) As String
Dim changeTo(3) As String
changeFrom() = Array("<word2>", "<word3>", "<word1>")
changeTo() = Array("value1", "value2", "value3")
test( changeFrom , changeTo)
End Sub
Generally -
does anyone know a better way for me to do this OTHER than "Basic" which is really driving me crazy.. I understand it can be done with Python, but I kind of wish there was an even easier way, problem is the word document has tables and things which need to be defined, so I can't just copy/paste the template in to a java class and modify it..
Thanks!
Callkeyword beforetest( changeFrom , changeTo)like in VBA?