Error When Closing Document Using Automation

Hi

I have been automating Calc for years from Visual FoxPro. It has worked
flawlessly until this week. Now the document close method often produces an
ole error 80010105. I was using verison 5.1 so I updated everything to the
latest 6.1 version but the problem persists. If I remove the Close() method
and just use Terminate() I get the same result that 30%-50% of the time it
crashes. The spreadsheet is created correctly but Libre Office crashes on
the Close() method. Does anyone have any ideas what might be the cause? I
am running on Windows Server 2012 64bit. I am using the 32bit version of
Libre Office.

If I try opening the document in Calc and makes some changes then use
"Close" from the File menu. I am prompted to save the document and
everything closes as expected. It only seems to occur when automating the
process.

laArgs(1).Name="FilterName"
laArgs(1).Value="MS Excel 97"
laArgs(2).Name="Overwrite"
laArgs(2).Value=.T.
ComArray(toBizObj.oMergeDoc,10)

toBizObj.oMergeDoc.storeAsURL(ConvertToURL(toParam.Destination),@laArgs)

toBizObj.oMergeDoc.close(1) <== Produces and error 30% - 50% of the time
toBizObj.oMerge.Terminate()

Thanks,
Simon

Sorry, I do not know what is going on, but....

DO you see anything different if you:

1. Pause for a few seconds before you call close? In the back of my mind I am wondering if for some silly reason, control returns to you before the save command finishes running.
2. out of curiousity, what value is in the isModified property?
3. I assume that you are calling terminate on the desktop object, is this correct?
4. Assuming you sleep a few seconds first, what happens if you call dispose on the document rather than close? I do not even know if the dispose method still exists, but, if it does. Note that you should not in general use dispose, but, that is what existed before close() was added to the API.

As you can see the .oMerge object is the Desktop and so yes I am calling
terminate on Desktop.

      .oMergeSrvMgr=CreateObject("com.sun.star.ServiceManager")
      .oMerge=.oMergeSrvMgr.createInstance("com.sun.star.frame.Desktop")

I will investigate the isModified property and get back to you.

I did try a 10 second delay before calling Close() method thinking like you
that perhaps it had not finished saving the document before I called close
but it made no difference.

Thanks
Simon