Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2007

Tip: Looking for answers? Try searching our database.

Word automation using vc++ 2005

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
antarikshv - 18 Sep 2007 11:41 GMT
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-

>Entries;

           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.)
Ben Schwehn - 18 Sep 2007 12:10 GMT
> 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
[quoted text clipped - 5 lines]
> (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
antarikshv - 18 Sep 2007 13:27 GMT
> > 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
[quoted text clipped - 20 lines]
>
> 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
Ben Schwehn - 18 Sep 2007 13:36 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.