Hi

I am trying to develop an application that creates an Excel file and then saves it. The excellent examples that are on-line demonstrate how to develop such an application and this wll works, in that I can populated the Excell sheet.

But the samples simply set the saved property, so that when Excel exits you are not prompted to save the file (which is great when testing the population side of things)

I have found some code (posted by Tom Frohman) that shows how to do the save. In essence it is (and this is what I am using)

//Save the work book.
{
VARIANT result;
VariantInit(&result);

VARIANT fname;
fname.vt = VT_BSTR;
fname.bstrVal=::SysAllocString(L"D:\\output.xls");

AutoWrap(DISPATCH_METHOD, &result, pXlSheet, L"SaveAs", 1, fname);

//VARIANT fformat;
//fformat.vt = VT_I4;
//fformat.lVal=-4143;
//AutoWrap(DISPATCH_METHOD, &result, pXlSheet, L"SaveAs", 2, fname, fformat);
}


There has been some discussion that this sometimes does not work. In my case (whih is also the problem reported by others), the save initially worked, but now I get the error

Idispatch("SaveAs"=00000785) failed w/err 0X800a0aa8


... and the save never works now (even after reboot).

Can anybody tell me what is wrong?

For information, which might be useful

- The discussion of the web question whether you need to pass fformat to Autowrap. I have tried both ways (see the commented out code above), with the same results.
- Sometimes, when I click OK on the message box from Autowrap, it takes ages to return as if it is doing something (tidying up memoy?), but sometimes it returns immediately.

I should also say, I am not that familiar with this type of programming.

Thanks

G