469,299 Members | 2,079 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

Word Automation-SaveAs Parameters Error

Hi,
I'm new to Automation and am currently trying a code from msdn

http://msdn2.microsoft.com/en-us/lib...ffice.10).aspx


to automate a word application(Office 2003) in VC++ using MFC. However,I keep getting an errror saying that the SaveAs parameter cannot take 11 parameters.

Can anyone help me?

priyanka
Jun 27 '07 #1
8 4610
weaknessforcats
9,208 Expert Mod 8TB
What does your call look like?
Jun 27 '07 #2
What does your call look like?
Hi..
Here is the function call..

oActiveDoc.SaveAs(COleVariant("e:\\priyanka\\testd oc2.doc"),
COleVariant((short)0),
vFalse, COleVariant(""), vTrue, COleVariant(""),
vFalse, vFalse, vFalse, vFalse,vFalse);

Its for word 2003 like i mentioned earlier.. Any idea how many params it takes??
Jun 29 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
oActiveDoc.SaveAs(COleVariant("e:\\priyanka\\testd oc2.doc"),
What is the function prototype of oActiveDoc.SaveAs()???

The only SaveAS I found was one in C# that takes 16 arguments.
Jun 29 '07 #4
Hi,
I'll try to find out more about the oActiveDoc.SaveAs method prototype. Meanwhile i started trying my hand on excel automation and i'm trying to insert data into the excel sheet. For data that is static i don't have a problem but for data that i want to insert at run time,the function that i lifted off msdn does not quite work.
I'm trying to insert strings and numbers of type double at runtime from a source. The function looks like :

void FillSafeArrayOfString(OLECHAR FAR* sz,int iRow,int iCol,COleSafeArray* sa)
{

VARIANT v;
long index[2];

index[0] = iRow;
index[1] = iCol;

VariantInit(&v); //DOUBLE dblVal; // VT_R8.
v.vt = VT_BSTR; //BSTR bstrVal; // VT_BSTR.
v.bstrVal = SysAllocString(sz);
sa->PutElement(index, v.bstrVal);
SysFreeString(v.bstrVal);
VariantClear(&v);

}

void FillSafeArrayOfDouble(double dval,int iRow,int iCol,COleSafeArray* sa)
{

VARIANT v;
long index[2];

index[0] = iRow;
index[1] = iCol;

VariantInit(&v); //DOUBLE dblVal; // VT_R8.
v.vt = VT_R8; //BSTR bstrVal; // VT_BSTR.
v.dblVal =dval;
sa->PutElement(index,&v);
VariantClear(&v);

}

The first function fills a string and the second a double in the specified cell. The function call looks like :

COleSafeArray saRet;
DWORD numElements[]={2,1}; //dimensions
saRet.Create(VT_BSTR, 2, numElements);

FillSafeArrayOfString(L"", 0, 0,&saRet); // in the "" would be the string i // want to place at runtime. I can't get rid of the 'L' and dyanamically placing it.
FillSafeArrayOfString(L"", 1, 0,&saRet);

range = sheet.GetRange(COleVariant("C2"), COleVariant("C3"));
range.SetValue2(COleVariant(saRet));

saRet.Detach();

Similarly for numbers : i want to insert the value dval1 into the cell F10.
COleSafeArray saRet;
double dval1;
dval1=m_dNumberOfRotatableBonds;
dval1=23.23;

DWORD numElements[]={1,1}; //dimensions
saRet.Create(VT_R8, 2, numElements);

FillSafeArrayOfDouble(dval1,0,0,&saRet);

range = sheet.GetRange(COleVariant("F10"), COleVariant("F10"));
range.SetValue2(COleVariant(saRet));

saRet.Detach();


This is not working. Could anyone please point out where i'm going wrong? Or else give me a reference to some code or another way of doing it?

Thanks a lot in advance for the efforts..
Priyanka
Jul 2 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
This code:
v.bstrVal = SysAllocString(sz);
sa->PutElement(index, v.bstrVal);
SysFreeString(v.bstrVal);
looks fishy.

First, you allocate a BSTR
Second, you call PutElement with the BSTR.
Third, you delete the BSTR.

I believe that you have just deleted the BSTR you allocated. PutElement() just passes the BTSR along as a pointer.

I do not believe you can delete this BSTR until there are no copies of the pointer to that BSTR left in your program.

I recommend using a smart pointer here. Check this article on Handle Classes.
Jul 2 '07 #6
This code:


looks fishy.

First, you allocate a BSTR
Second, you call PutElement with the BSTR.
Third, you delete the BSTR.

I believe that you have just deleted the BSTR you allocated. PutElement() just passes the BTSR along as a pointer.

I do not believe you can delete this BSTR until there are no copies of the pointer to that BSTR left in your program.

I recommend using a smart pointer here. Check this article on Handle Classes.

Thanks.. I got rid of those two functions and tried a simpler one using Setvalue2(). It worked!
Jul 4 '07 #7
Hi,
I'm new to Automation and am currently trying a code from msdn

http://msdn2.microsoft.com/en-us/lib...ffice.10).aspx


to automate a word application(Office 2003) in VC++ using MFC. However,I keep getting an errror saying that the SaveAs parameter cannot take 11 parameters.

Can anyone help me?

priyanka


HI,
u were specifying abt automation. I have get data and write to a file say excel, in real time will this automation wil be useful. i am using TCp/IP socket for client server connection. Plz do reply.
Jul 4 '07 #8
HI,
u were specifying abt automation. I have get data and write to a file say excel, in real time will this automation wil be useful. i am using TCp/IP socket for client server connection. Plz do reply.
Hi,
I really have no idea.. U should try asking around someone else in the forum.I'm a newbie too.
Priyanka
Jul 11 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Daniel | last post: by
reply views Thread by mharris | last post: by
2 posts views Thread by Radek | last post: by
6 posts views Thread by Mark Rae | last post: by
22 posts views Thread by liya.tansky | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.