Posted to microsoft.public.excel.programming
|
|
Can't get Excel SaveAs dialog to show
Hi M'
You need to use the name for the automation object before
the application call. Maybe like this:
Hr.Application.Dialogs("xlDialogSaveAs").Show sFileName
-----Original Message-----
I'm trying to show the Excel SaveAs dialog from an ATL
app.
In VB, the following works fine:
Application.Dialogs("xlDialogSaveAs").Show sFileName
But in ATL, I've had all sorts of trouble with getting
this
to work. Here's what I have right now:
CComPtr<IDispatch m_pExcel;
HRESULT hr = m_pExcel.CoCreateInstance
(L"Excel.Application", NULL,
CLSCTX_SERVER);
CComDispatchDriver cddExcel = m_pExcel;
CComVariant vTrue(TRUE);
hr = cddExcel.PutPropertyByName(L"Visible",&vTrue);
CComVariant cvDialogs;
cddExcel.GetPropertyByName(L"Dialogs", &cvDialogs);
CComDispatchDriver cddDialogs = cvDialogs.pdispVal;
CComVariant cvCount;
hr = cddDialogs.GetPropertyByName(L"Count",&cvCount);
DISPID dwDispID;
hr = cddDialogs.GetIDOfName(L"Item", &dwDispID);
CComVariant cvIndex(5); //xlDialogSaveAs
DISPPARAMS dispparams = { (VARIANT*)&cvIndex, NULL, 1,
0 };
CComVariant cvDialog;
cddDialogs-Invoke(dwDispID, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET |
DISPATCH_METHOD, [i]
&dispparams, &cvDialog, NULL, NULL);
CComDispatchDriver cddDialog = cvDialog.pdispVal;
CComVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR);
CComVariant cvResult;
VARIANT vArgsShow[30];
memset(vArgsShow, 0, sizeof(VARIANT) * 30);
for(int i=0;i<30;i++)
{
vArgsShow = vOpt;
}
CComVariant cvDocText("C:\\testing.xls");
vArgsShow[29] = cvDocText; //document_text
CComVariant cvTypeNum(1);
vArgsShow[28] = cvTypeNum; //type_num
CComVariant cvProtPwd("");
vArgsShow[27] = cvProtPwd; //prot_pwd
CComVariant cvBackup(FALSE);
vArgsShow[26] = cvBackup; //backup
CComVariant cvWriteResPwd("");
vArgsShow[25] = cvWriteResPwd; //write_res_pwd
CComVariant cvReadOnlyRec(FALSE);
vArgsShow[24] = cvReadOnlyRec; //read_only_rec
hr = cddDialog.InvokeN(L"Show", vArgsShow, 30,
&cvResult);
return 0;
The excel instance starts up fine, I get the Dialogs
object,
it has a count of over 700 dialogs, and I'm able to get
the
dialog xlDialogSaveAs.
However, I can't get the invoke of the Show method to
work.
I've tried all optional parms, just filename, parameters
in
forward and backward order, all parameters. Nothing seems
to work.
Anybody have any ideas whats wrong here?
Thanks,
-M-
.
|