Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I open a word document in C++ with a CNiWordApplication object?

Hello,
For an application, i need to open a word document using VisualC++ and CNiWord classes (CNiWordApplication, CNiWordDocument...). I successed to create a new CNiWordDocument with the CNiWordApplication CreateDocument() function. But when using the OpenDocument() I have error message about violation error. Must I create another objet before calling the OpenDocument() function? Is it possible to have an example of code to open a word document?

Thank you for your help.
0 Kudos
Message 1 of 3
(3,879 Views)
I tried the following code to open a doc file in an MFC application.

CNiWordApplication word;
CNiWordDocument doc = word.OpenDocument("c:\\books.doc");

This worked fine for me. I tried this with Word 2003 and Measurement Studio 7.1

Try running one of the shipping examples. You can find examples for this under ..\MeasurementStudio\VCNET\Examples\Office\

Hope this helps.
Bilal Durrani
NI
0 Kudos
Message 2 of 3
(3,868 Views)
There are two examples that ship with Measurement Studio that use the word classes. The two examples are installed to the [installdir]\VCNET\Examples\Office and are called WordAdvanced and WordReport. To open a document you would call OpenDocument on the CNiWordApplication class like:

CNiWordApplication m_word(true);
CNiWordDocument m_doc_1 = m_word.OpenDocument(pathToDoc);
0 Kudos
Message 3 of 3
(3,863 Views)