473,545 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Starting Word or Excel application via COM

Hi together,
I am using the following code in Visual Basic to open Word or Excel
applications:

Word:
Dim w As Word.Applicatio n
w = CType(CreateObj ect("Word.appli cation"), Word.Applicatio n)
w.Application.D ocuments.Open(" test.doc")
With w.Application.S election
[... whatever ...]
End With
w.Application.A ctiveDocument.S aveAs("test2.do c")
w.Documents.Clo se()
w.quit

Excel:
Dim xlapp As Excel.Applicati on
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
xlapp = CType(CreateObj ect("Excel.appl ication"), Excel.Applicati on)
xlbook = CType(xlapp.Wor kbooks.Add, Excel.Workbook)
xlsheet = CType(xlbook.Wo rksheets(1), Excel.Worksheet )
with xlssheet
[... whatever ...]
end with
xlapp.quit()

Now I'm trying to do the same thing in Visual C++ (Visual Studio .net 2003).

Word:
Interop::Word:: Application* w=new Interop::Word:: ApplicationClas s();
Interop::Word:: Document* wd =new Interop::Word:: DocumentClass() ;

This starts a new instance of Word. OK.

Then I tried to open an existing document or to create a new one:
Interop::Word:: Documents::Add
w->Application->Documents->Open
but these functions ask for a lot of parameters. I've got no idea what
to use. I tried to put some "NULL" in it, but it was not working.

The same problem with Excel:
Interop::Excel: :Application* ex=new Interop::Excel: :ApplicationCla ss();
starts Excel.
But everything like this is not working:
Interop::Excel: :Workbook* wb=ex->add_NewWorkboo k();
Interop::Excel: :Workbook* wb=new Interop::Excel: :Workbook();

I spent a lot of time searching MSDN and Google, but I did not find any
good example that was working.

Thank you for tips and/or examples, Bernd
Danke für Tips und Beispiele, Bernd

--
BM Computer-Services, Bergmannstr. 66, 10961 Berlin
Webdesign, Internet, Layout und Grafik
Tel.: 030/20649400, mobil 0175/7419517, Fax: 030/20649401
Web: http://www.bmservices.de, eMail: ko*****@bmservi ces.de
Nov 17 '05 #1
1 3020
Declare:
object missing = System.Type.Mis sing;

and then put "ref missing" instead of null.

- Abhijeet Dev
Andale Inc

"Bernd Muent" <ko*****@bmserv ices.de> wrote in message
news:41******** *************@n ews.highwayone. de...
Hi together,
I am using the following code in Visual Basic to open Word or Excel
applications:

Word:
Dim w As Word.Applicatio n
w = CType(CreateObj ect("Word.appli cation"), Word.Applicatio n)
w.Application.D ocuments.Open(" test.doc")
With w.Application.S election
[... whatever ...]
End With
w.Application.A ctiveDocument.S aveAs("test2.do c")
w.Documents.Clo se()
w.quit

Excel:
Dim xlapp As Excel.Applicati on
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
xlapp = CType(CreateObj ect("Excel.appl ication"), Excel.Applicati on)
xlbook = CType(xlapp.Wor kbooks.Add, Excel.Workbook)
xlsheet = CType(xlbook.Wo rksheets(1), Excel.Worksheet )
with xlssheet
[... whatever ...]
end with
xlapp.quit()

Now I'm trying to do the same thing in Visual C++ (Visual Studio .net
2003).

Word:
Interop::Word:: Application* w=new Interop::Word:: ApplicationClas s();
Interop::Word:: Document* wd =new Interop::Word:: DocumentClass() ;

This starts a new instance of Word. OK.

Then I tried to open an existing document or to create a new one:
Interop::Word:: Documents::Add
w->Application->Documents->Open
but these functions ask for a lot of parameters. I've got no idea what to
use. I tried to put some "NULL" in it, but it was not working.

The same problem with Excel:
Interop::Excel: :Application* ex=new Interop::Excel: :ApplicationCla ss();
starts Excel.
But everything like this is not working:
Interop::Excel: :Workbook* wb=ex->add_NewWorkboo k();
Interop::Excel: :Workbook* wb=new Interop::Excel: :Workbook();

I spent a lot of time searching MSDN and Google, but I did not find any
good example that was working.

Thank you for tips and/or examples, Bernd
Danke für Tips und Beispiele, Bernd

--
BM Computer-Services, Bergmannstr. 66, 10961 Berlin
Webdesign, Internet, Layout und Grafik
Tel.: 030/20649400, mobil 0175/7419517, Fax: 030/20649401
Web: http://www.bmservices.de, eMail: ko*****@bmservi ces.de

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4067
by: Chris | last post by:
Hi, - How can I open an existing word document from a C#-client and manipulate that document from within the C#-client ? - How can I open an excel document that is embedded in a word-document ? - How do I read the value of a cell within an Excel document ? I tried using a Word-OLB file (object library) that I set a reference to but...
4
3390
by: Chris | last post by:
Hi, everything works apart from the last line :-(( rng.Value2.ToString() An exception is thrown : "Old format or invalid type library" It gets compiled though (so he recognizes the property 'Value2'). So I suppose I'm using a incompatible type lib. I'm using Excel 2002 : Excel 10.0 Object Library
0
963
by: Sherpa Tenzing | last post by:
I am trying to load Word Object to do some VBA automation within my ASP.NET webservice. I understand it is not recommended but it will only ocassionally used. I am not able to create the object. I get the following error System.Exception occurred in Microsoft.VisualBasic.CreateObject Cannot create ActiveX component. at...
4
3238
by: Lisa | last post by:
Hi - I'm able to open excel workbooks and word documents, but I can't seem to copy excel charts, named ranges, etc. to a word document. Anyone know of good reference material in this area? What little documentation I've been able to find focuses on using only one office app at a time. Thanks for your help
3
2344
by: herman404 | last post by:
Hi everyone, I have data coming to me in the form of Word and Excel files, and I need to place this data into a SQL Server database. The Word file will be coming in text which is similiar to an Excel sheet, but instead of being comma delimited, it will be delimited by spaces. Regarding the Word document, I can set rules for the field...
7
9019
by: vbnetdev | last post by:
My boss wants this done in a day. I would be happy with a week! Anyway, I have a dataset filled with data and need to populate an MS word chart with it when writing a report. Any tutorials or suggestions would be great. Sample data at http://www.kjmsolutions.com/sample.txt
12
3437
by: Steve | last post by:
I've been building an application that will merge fields in a text file with a word template, save the resulting word file out to the user's hard drive, and then email the file as an attachment. The problem I'm having is that I can't delete the word file I saved at the end of the process due to the file being locked by the email process. It...
14
5271
by: Alan T | last post by:
These are the codes I created a document: _WordApp = new Interop.Word.Application(); _WordApp.Visible = false; _WordDoc = new Document(); _Missing = System.Reflection.Missing.Value;
1
2928
by: webgirl | last post by:
Hi everyone, I have a weird problem with some Word/Excel automation code that I run from Access (not sure if I should therefore post this in the Access forum..? Thought I'd try here first) Basically, the code either opens a document (if it exists) or creates it from a template if it doesn't. Docs can be Word or Excel docs. The weird part...
0
7475
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7437
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...
0
7771
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...
0
5982
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...
0
4958
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...
0
3465
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1900
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
1
1023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.