I'm maintaining an application that uses OLE automation to embed Word. However, when the tab containing the document is closed under certain circumstances the Word process will hang on to the file - even after closing our application.
I've been searching for how to close a file in Word, and I've come across https://msdn.microsoft.com/en-us/library/office/ff196343.aspx, which indicates there's some sort of Close
method that I would like to call, but it doesn't appear to be working.
Word is opened like so:
clientSite = new OleClientSite(frame, SWT.NONE, Word97To2003ClassId, file);
automation = new OleAutomation(clientSite);
And I can call automation.getIDsOfNames(new String[]){ "Close" })[0]
which returns 1105
. But when I call automation.invoke(1105)
it still keeps my document open. Any idea how I could close my document when my frame closes?
From my experience there are a lot of API methods which simply don't work. Probably "close" is one of them.
Maybe you can make sure that the OleClientSite
is disposed prior of the tab or application.
I had a problem with a dialog where I did the following (not so nice but works):
@Override
public boolean close() {
// make sure clientSite is disposed first
if (clientSite != null && !clientSite.isDisposed()) {
clientSite.dispose();
}
return super.close();
}