473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 4851
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

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

Similar topics

6
by: Colleyville Alan | last post by:
I have an application that has an Access table that stores the locations of slides in a Powerpoint file. This used to work fine when there were about 4 files and 200 slides. The database would...
2
by: kids | last post by:
Does anybody know any reason which could cause Ms. word automation to crash? I try to call word automation to open a document and use find and replace function. For some reason it works but I...
4
by: Daniel | last post by:
Hello, i have a problem with the word automation from c#. First, i want to mention, that i don't have any dependencies from word in my c#-project, i want to use the system.reflection model to...
0
by: mharris | last post by:
I need help with merging two Word documents into one through C# code. The problem isn't so much getting the documents put into one as it is maintaining the appropriate formatting, or rather...
2
by: Radek | last post by:
Hi, I have got such problem: in my directory "C:\folder" I have 3 files in MS WORD (having tables, images etc), these are: "1.doc", "2.doc", "3.doc". I want to write an application (C# of...
5
by: Daniel Walzenbach | last post by:
Hi, I need to know how I could populate a word file from within ASP.NET and stream it out to some user (I can rely on all users have at least Word XP installed). The preferable solution would be...
3
by: Charles Law | last post by:
Word has a property BuiltinDocumentProperties, which (in VBA) returns a DocumentProperties collection. In VB.NET, using Word automation, it returns a _ComObject. I have tried to cast this to...
6
by: Mark Rae | last post by:
Hi, My client has asked me to provide a "quick and dirty" way to export the contents of a DataGrid to both Excel for analysis and Word for editing and printing, so I'm investigating client-side...
22
by: liya.tansky | last post by:
Hello, I'm developing an intranet (win XP, .NET 2, Visual Studio 2005, Microsoft.Office.Interop.Word.dll in references) and needed to implement find-replace in word doc before sending letter and...
1
by: apondu | last post by:
Hi, can someone help me and provide me the information on how to supress the default action of the shortcut keys of word during word automation. I am using C#.Net I have written a code but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.