I am using the following macro to update the table of contents.
sub updater(optional strArg$) dim document as object dim dispatcher as object dim Doc As Object dim FileProperties(1) As New com.sun.star.beans.PropertyValue dim Url As String Url = ConvertToUrl(strArg) FileProperties(0).Name = "Hidden" FileProperties(0).Value =True Doc = StarDesktop.loadComponentFromURL(Url, "_blank", 0, FileProperties()) document = Doc.CurrentController.Fram dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") oIndexes = Doc.getDocumentIndexes() for i = 0 to oIndexes.getCount() - 1 oIndexes (i).update next i dispatcher.executeDispatch(document, ".uno:Save", "", 0, Array()) Doc.close(True)` end sub
This macro is getting called through command line.
soffice --invisible --headless "macro:///Standard.Module1.updater(<<AbsolutePathToFile>>)
This macro works great if this was put into the Modue1 through the GUI. However in a headless environment that’s not possible and is put into it by modifying the Module1.xba file.
The macro that works when put through GUI does not work anymore when directly inserted into Module1.xba file. However if I put mkdir command at the start and and the end to see if the macro is getting executed, it does produce the directories. But the file is never updated.
Any ideas or suggestions would be greatly appreciated!
[Edit - Opaque] moved code into a single box of preformatted text