473,716 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Word Automation-SaveAs Parameters Error

5 New Member
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(Off ice 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 4870
weaknessforcats
9,208 Recognized Expert Moderator Expert
What does your call look like?
Jun 27 '07 #2
priyankalakhe
5 New Member
What does your call look like?
Hi..
Here is the function call..

oActiveDoc.Save As(COleVariant( "e:\\priyanka\\ testdoc2.doc"),
COleVariant((sh ort)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 Recognized Expert Moderator Expert
oActiveDoc.Save As(COleVariant( "e:\\priyanka\\ testdoc2.doc"),
What is the function prototype of oActiveDoc.Save As()???

The only SaveAS I found was one in C# that takes 16 arguments.
Jun 29 '07 #4
priyankalakhe
5 New Member
Hi,
I'll try to find out more about the oActiveDoc.Save As 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 FillSafeArrayOf String(OLECHAR FAR* sz,int iRow,int iCol,COleSafeAr ray* 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(ind ex, v.bstrVal);
SysFreeString(v .bstrVal);
VariantClear(&v );

}

void FillSafeArrayOf Double(double dval,int iRow,int iCol,COleSafeAr ray* 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(ind ex,&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);

FillSafeArrayOf String(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.
FillSafeArrayOf String(L"", 1, 0,&saRet);

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

saRet.Detach();

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

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

FillSafeArrayOf Double(dval1,0, 0,&saRet);

range = sheet.GetRange( COleVariant("F1 0"), COleVariant("F1 0"));
range.SetValue2 (COleVariant(sa Ret));

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 Recognized Expert Moderator Expert
This code:
v.bstrVal = SysAllocString( sz);
sa->PutElement(ind ex, 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
priyankalakhe
5 New Member
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
gnanapoongothai
62 New Member
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(Off ice 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
priyankalakhe
5 New Member
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
3957
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 open all four PPT files at once, and would loop through queriers for ever client and create custom presentations. Now there are 8 files, nearly 500 slides and the computer is bogging down with trying to open them all at once. I know that Access...
2
2612
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 don't know why it crash some time.
4
7680
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 handle the automation. So, i'm using the following code to create a new word document: ---Code---
0
6298
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 reformating, after the merge. This is a full description of my needs. I have a C# class library that creates two Crystal Reports, and then exports them to the harddrive as Word documents. One's orientation is landscape, the other is portrait. I then...
2
2621
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 course) which will merge the contents of files which I will point ie. 1.doc and 2.doc into one file: "12.doc" I've just tried to find smth in MSDN help, and in google archive of programing groups but still I don't know how to do it:(
5
2527
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 to have a word template on the server which is populated in the asp.net application and then streamed out to the user. Also acceptable would be to open a template on the client's computer using automation and fill this file (if this is possible)....
3
5606
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 DocumentProperties, but I get an invalid cast exception. In Explorer, I can right click a Word document, click Properties, and I get a tabbed dialog with Custom and Summary tabs. These tabs show me the built in document properties of the document. ...
6
2406
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 automation. N.B. the environment is a totally enclosed intranet, all the client machines have WinXP, IE6 and Office Pro 2003 with all the latest SPs, and the IE security settings are sufficient to allow the Local Intranet Zone to instantiate...
22
2270
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 it worked fine on my station. I've go it fine on my station, and it doesn't work at all on the web server. 1. What should be the configuration of the server? There is .net SDK 2 and I've installed the oxppia.exe there. And changed the...
1
1969
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 it generates a exception "Object Reference not set
0
8718
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9105
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9047
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7980
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6647
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5969
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3177
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2119
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.