Word automation using vc++ 2005

A

antarikshv

I want to use VC++.Net 2005 to automate Microsoft word.I have checked
the code available online for C# but the code could not be translated
as it is to VC++ as the compiler was giving errors for the properties
could not be found. Below is the code where i am stuck,Please help.

Object ^ missing = System::Reflection::Missing::Value;
Object ^ EndODoc = "\\endofdoc";

Word::_Application ^ myWord;// = new Word.Application();
int return_Result = 0;

// Create a word object that we can manipulate
Word::Application ^ Word_App;
Word::_Document ^ Word_doc;
try
{
Word_App = gcnew Word::Application();
Word_doc = gcnew Word::Document();
}
catch (Exception ^ e1)
{
return_Result = 1;
//goto Exit;
}

Word::AutoCorrect ^ autocorrect = Word_App->AutoCorrect;
Word::AutoCorrectEntries ^ autoEntries = autocorrect-

String ^ theEnd = "\nThe End";
autoEntries->Add("Introduction", "Introduction");

Word::Documents ^ Docs = Word_App->Documents;

Word_App->Visible = true;
Word::_Document ^ my_Doc = (Word::_Document ^)Word_doc;
Word_doc = Docs->Add(missing,missing,missing,missing);

Object ^start;
Object ^end;
Word::Range ^range = Word_doc->Range( missing, missing);

Word::paragraph ^ pgs;// = gcnew Word::paragraph();
pgs = Word_doc->Content->Paragraphs->Add(missing);
pgs->Range->Text = "Helllo";

(The Range property is present for the Paragraph class but its not
accessible.)
 
B

Ben Schwehn

antarikshv said:
I want to use VC++.Net 2005 to automate Microsoft word.I have checked
the code available online for C# but the code could not be translated
as it is to VC++ as the compiler was giving errors for the properties
could not be found. Below is the code where i am stuck,Please help.
[snip]
pgs->Range->Text = "Helllo";

(The Range property is present for the Paragraph class but its not
accessible.)


What error do you get?

pgs->Range->Text = "Helllo";

doesn't even compile for me, replaced with what the compiler error (
error C3293: 'Range': use 'default' to access the default property
(indexer) for class 'Microsoft::Office::Interop::Word::paragraph') tells
you do do:

pgs->default->default = "Helllo";

is that your problem? Works fine for me anyways (using word 11.0)

Ben
 
A

antarikshv

antarikshv said:
I want to use VC++.Net 2005 to automate Microsoft word.I have checked
the code available online for C# but the code could not be translated
as it is to VC++ as the compiler was giving errors for the properties
could not be found. Below is the code where i am stuck,Please help.
[snip]
pgs->Range->Text = "Helllo";
(The Range property is present for the Paragraph class but its not
accessible.)

What error do you get?

pgs->Range->Text = "Helllo";

doesn't even compile for me, replaced with what the compiler error (
error C3293: 'Range': use 'default' to access the default property
(indexer) for class 'Microsoft::Office::Interop::Word::paragraph') tells
you do do:

pgs->default->default = "Helllo";

is that your problem? Works fine for me anyways (using word 11.0)

Ben

Hey Ben thanks a lot for the help. atleast now I am able to start with
putting text onto the word document. There is another solution i am
seeking. I wanted to add text into the tables and the code i am
referring for this is in C#. For your reference i am putting the code
here, but if you know how to do that then please let me know


object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark
*/


The code
//Insert a 3 x 5 table, fill it with data, and make the
first row
//bold and italic.
Word.Table oTable;
Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref
oEndOfDoc).Range;
oTable = oDoc.Tables.Add(wrdRng, 3, 5, ref oMissing, ref
oMissing);
oTable.Range.ParagraphFormat.SpaceAfter = 6;
int r, c;
string strText;
for (r = 1; r <= 3; r++)
for (c = 1; c <= 5; c++)
{
strText = "r" + r + "c" + c;
oTable.Cell(r, c).Range.Text = strText;
}
oTable.Rows[1].Range.Font.Bold = 1;
oTable.Rows[1].Range.Font.Italic = 1;

Also is there any method to access the EndOfDocument property from VC+
+.Net
 
B

Ben Schwehn

referring for this is in C#. For your reference i am putting the code
here, but if you know how to do that then please let me know

What's wrong with the code?

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top