Strange issue with macro in headless mode

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

To see what is going on, it may help to log messages to a file. In Python, I would start with import logging and then add lines such as logging.debug(strArg). In Basic, you may have to write your own logging routines.

Does the file modified date change? If so, then perhaps there’s a problem updating the indexes. If not, then .uno:Save may be where the problem occurs.

Hi Jim, Thanks for your comment really appreciate it.

In Basic, you may have to write your own logging routines.

I will look into it. But because I was unable to find resources I put mkdir command to see if the macro was effectively executed. I try to look deeper into it.

The timestamp is not changed at all. I would like to check if .uno:Save or any other line in fact returns an error/fails but couldn’t find any thing on catching errors.

In Python, an error handling example is try... except com.sun.star.uno.RuntimeException. In Basic, there is On Error GoTo … Resume.

Have you solved this problem yet?
If yes give me a solution, I am also facing this problem