
Save method fails in Word XP automation
Hi,
I have a problem while trying to use Save a document in Word XP through
automation. The Save method fails only when a document is opened through an
IE browser. The error message which I get is " The Save Method or Property
is not available because it is in another application". The same program
works with Word 2000 & Word 97 without any problem. I am listing bellow the
code for the program
COleVariant vTrue((short)TRUE),
vFalse((short)FALSE),
vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
::CoInitialize(NULL);
// Translate server ProgID into a CLSID. ClsidFromProgID
// gets this information from the registry.
CLSID clsid;
CLSIDFromProgID(L"Word.Application", &clsid);
// Get an interface to the running instance, if any..
IUnknown *pUnk;
HRESULT hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk);
ASSERT(!FAILED(hr));
// Get IDispatch interface for Automation...
IDispatch *pDisp;
hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDisp);
ASSERT(!FAILED(hr));
// Release the no-longer-needed IUnknown...
pUnk->Release();
_Application oApp( pDisp);
//Get the active document's IDispatch
_Document oDoc = oApp.GetActiveDocument();
//Call the Save method through IDispatch
oDoc.Save(); <--------------------------METHOD FAILS
/* oDoc.SaveAs(COleVariant("c:\\doc1.doc"), <----------SAVEAS METHOD
SUCCEEDS
COleVariant((short)0),
vFalse, COleVariant(""), vTrue, COleVariant(""),
vFalse, vFalse, vFalse, vFalse, vFalse);
*/
Can anyone tell me why the method fails and what method should i use to save
document?.
Thanks,
Bala.M