Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MS word automation examples

MS word automation examples

Scheduled Pinned Locked Moved C / C++ / MFC
testingtoolstutorialquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tiziacaia
    wrote on last edited by
    #1

    Do somebody know where i can find a word automation example to write a .doc file? Thanks a lot tiziacaia

    V D 2 Replies Last reply
    0
    • T tiziacaia

      Do somebody know where i can find a word automation example to write a .doc file? Thanks a lot tiziacaia

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      find your office "compiled help" file. This file has the .chm extension. Here you can read up about the objects ... It will not really get you started though. Search on MSDN and google and idd hope that somebody has a sample code. good luck. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

      1 Reply Last reply
      0
      • T tiziacaia

        Do somebody know where i can find a word automation example to write a .doc file? Thanks a lot tiziacaia

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        MSDN article Q178749 has an Excel example. Step 9 is the important one as you'll use Word's type library instead of Excel's. Creating an instance of the (Word) _Application object and using its methods will be the same, though.

        _Application app;
        app.CreateDispatch(_T("Word.Application"));
        Documents docs = app.GetDocuments();
        CString strFilename(_T("A letter to home.doc"));
        _Document doc = docs.Open(COleVariant(strFileName), ...);
        ...


        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

        T 1 Reply Last reply
        0
        • D David Crow

          MSDN article Q178749 has an Excel example. Step 9 is the important one as you'll use Word's type library instead of Excel's. Creating an instance of the (Word) _Application object and using its methods will be the same, though.

          _Application app;
          app.CreateDispatch(_T("Word.Application"));
          Documents docs = app.GetDocuments();
          CString strFilename(_T("A letter to home.doc"));
          _Document doc = docs.Open(COleVariant(strFileName), ...);
          ...


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          T Offline
          T Offline
          tiziacaia
          wrote on last edited by
          #4

          Thanks a lot for the answers but now i get a new problem: error C2065: '_Application' : undeclared identifier I added word's type library, with classes _Application, _Document and Documents. I tryied to import the .h files but don't work. I don't understand. Thanks

          D 1 Reply Last reply
          0
          • T tiziacaia

            Thanks a lot for the answers but now i get a new problem: error C2065: '_Application' : undeclared identifier I added word's type library, with classes _Application, _Document and Documents. I tryied to import the .h files but don't work. I don't understand. Thanks

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            tiziacaia wrote: I tryied to import the .h files but don't work. You should have included, not imported, msword9.h, preferably in the project's stdafx.h file.


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

            T 1 Reply Last reply
            0
            • D David Crow

              tiziacaia wrote: I tryied to import the .h files but don't work. You should have included, not imported, msword9.h, preferably in the project's stdafx.h file.


              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

              T Offline
              T Offline
              tiziacaia
              wrote on last edited by
              #6

              I write "import" but i used correctly the "include". I don't have msword9.h but only CApplication.h, CDocuemnts.h and CDocuments0.h I added the .h files like you say in the stdafx.h but don't work.

              D 1 Reply Last reply
              0
              • T tiziacaia

                I write "import" but i used correctly the "include". I don't have msword9.h but only CApplication.h, CDocuemnts.h and CDocuments0.h I added the .h files like you say in the stdafx.h but don't work.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                When you added Word's type library, it would have created a .h and a .cpp file and added those to the project. Can you confirm this?


                "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                T 1 Reply Last reply
                0
                • D David Crow

                  When you added Word's type library, it would have created a .h and a .cpp file and added those to the project. Can you confirm this?


                  "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                  T Offline
                  T Offline
                  tiziacaia
                  wrote on last edited by
                  #8

                  Yes, but the created files are only: CApplication.h,CDocuments.h and CDocument0.h

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups