The following partial VB script assigns a DataSourceName to a mailmerge template and then merges to create a new document. At the moment that the DataSourceName is assigned, an OS level read-write lock is applied to the .ODB file - prohibiting other users from using it. Note that even after the original template is disposed, the file lock remains until Writer is completely closed and the desktop instance is unloaded.
Environment: Windows Server 2019. LibreOffice 7.3.7.2 (x64)
The kludge/workaround is to perform the merge, save the output document, completely close the Desktop, and then re-load it with the final document.
I’m currently considering using a headless instance to perform the mailmerge on another machine, and then only ever open the final document on the user’s machine.
Any other suggestions?
sName = Substitute(strFilename, “\”, “/”)
Set objMailMerge = oSM.createInstance(“com.sun.star.text.MailMerge”)
objMailMerge.DocumentURL = sName
objMailMerge.DataSourceName = “CSV”
objMailMerge.Command = “MailMergeData”
objMailMerge.CommandType = 0
objMailMerge.OutputType = 4
objMailMerge.SaveAsSingleFile = 1
Set newDoc = objMailMerge.Execute(Array())
objMailMerge.dispose
oDoc.dispose
newDoc.getCurrentController().getFrame().getContainerWindow().setVisible (True)
Set oDoc = newDoc