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
  1. Home
  2. General Programming
  3. C#
  4. Word object

Word object

Scheduled Pinned Locked Moved C#
tutorialquestion
15 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.
  • H Offline
    H Offline
    hazzem elrefai
    wrote on last edited by
    #1

    i have got code that use Microsoft spell checker, but when i tryed to compile it i have got erorr in this line: //////////////// using Word; ////////////// the erorr is :- "The type or namespace name 'Word' could not be found (are you missing a using directive or an assembly reference?)" so i wanna know how to make my application show word class and thnx in advance

    C 1 Reply Last reply
    0
    • H hazzem elrefai

      i have got code that use Microsoft spell checker, but when i tryed to compile it i have got erorr in this line: //////////////// using Word; ////////////// the erorr is :- "The type or namespace name 'Word' could not be found (are you missing a using directive or an assembly reference?)" so i wanna know how to make my application show word class and thnx in advance

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      using Office = Microsoft.Office.Core; using Word = Microsoft.Office.Interop.Word; --Colin Mackay--

      "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

      H 1 Reply Last reply
      0
      • C Colin Angus Mackay

        using Office = Microsoft.Office.Core; using Word = Microsoft.Office.Interop.Word; --Colin Mackay--

        "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

        H Offline
        H Offline
        hazzem elrefai
        wrote on last edited by
        #3

        i typed the full path but the code doesn't compile at all this code is: private void btn_create_Click(object sender, System.EventArgs e) { Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application(); l_status.Text+="object instantiated\n"; object Source="c:\\abc\\dat.doc"; object Target="c:\\abc\\Target.rtf"; object Unknown =Type.Missing; // Source document open here // Additional Parameters are not known so that are // set as a missing type newApp.Documents.Open(ref Source,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown,ref Unknown); l_status.Text+="file opened\n"; // Specifying the format in which you want the output file object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF; l_status.Text+="new format created"; //Changing the format of the document newApp.ActiveDocument.SaveAs(ref Target,ref format, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown); l_status.Text+="new file saved \n"; // for closing the application newApp.Quit(ref Unknown,ref Unknown,ref Unknown); l_status.Text+="object closed \n"; } =============================================== the error message is : An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in code_container.exe Additional information: The server threw an exception.

        C 1 Reply Last reply
        0
        • H hazzem elrefai

          i typed the full path but the code doesn't compile at all this code is: private void btn_create_Click(object sender, System.EventArgs e) { Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application(); l_status.Text+="object instantiated\n"; object Source="c:\\abc\\dat.doc"; object Target="c:\\abc\\Target.rtf"; object Unknown =Type.Missing; // Source document open here // Additional Parameters are not known so that are // set as a missing type newApp.Documents.Open(ref Source,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown,ref Unknown); l_status.Text+="file opened\n"; // Specifying the format in which you want the output file object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF; l_status.Text+="new format created"; //Changing the format of the document newApp.ActiveDocument.SaveAs(ref Target,ref format, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown); l_status.Text+="new file saved \n"; // for closing the application newApp.Quit(ref Unknown,ref Unknown,ref Unknown); l_status.Text+="object closed \n"; } =============================================== the error message is : An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in code_container.exe Additional information: The server threw an exception.

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          hazzem elrefai wrote: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in code_container.exe Indicates that the code has compiled. You have a runtime error. What line did this happen on? --Colin Mackay--

          "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

          H 2 Replies Last reply
          0
          • C Colin Angus Mackay

            hazzem elrefai wrote: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in code_container.exe Indicates that the code has compiled. You have a runtime error. What line did this happen on? --Colin Mackay--

            "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

            H Offline
            H Offline
            hazzem elrefai
            wrote on last edited by
            #5

            the error in the main finction line : and i couldn't get any meaningful data from this erorr static void Main() { Application.Run(new MainForm()); }

            C 1 Reply Last reply
            0
            • C Colin Angus Mackay

              hazzem elrefai wrote: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in code_container.exe Indicates that the code has compiled. You have a runtime error. What line did this happen on? --Colin Mackay--

              "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

              H Offline
              H Offline
              hazzem elrefai
              wrote on last edited by
              #6

              the erorr message say: the server threw an exception and nothing more.

              1 Reply Last reply
              0
              • H hazzem elrefai

                the error in the main finction line : and i couldn't get any meaningful data from this erorr static void Main() { Application.Run(new MainForm()); }

                C Offline
                C Offline
                Colin Angus Mackay
                wrote on last edited by
                #7

                I suspect this is where the exception was CAUGHT. Not where it was generated/thrown.

                static void Main()
                {
                try
                {
                Application.Run(new MainForm());
                }
                catch(Exception e)
                {
                Debug.WriteLine(e.Message);
                Debug.WriteLine(e.StackTrace);
                }
                }

                Will write to the output the location that the error was generated. This will help with solving the problem. --Colin Mackay--

                "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

                H H 2 Replies Last reply
                0
                • C Colin Angus Mackay

                  I suspect this is where the exception was CAUGHT. Not where it was generated/thrown.

                  static void Main()
                  {
                  try
                  {
                  Application.Run(new MainForm());
                  }
                  catch(Exception e)
                  {
                  Debug.WriteLine(e.Message);
                  Debug.WriteLine(e.StackTrace);
                  }
                  }

                  Will write to the output the location that the error was generated. This will help with solving the problem. --Colin Mackay--

                  "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

                  H Offline
                  H Offline
                  hazzem elrefai
                  wrote on last edited by
                  #8

                  i used try catch statements and the erorr is comming from this line: newApp.Documents.Open(ref Source,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown, ref Unknown,ref Unknown,ref Unknown,ref Unknown); plz keep with me and this will be apreciated thnx another time

                  1 Reply Last reply
                  0
                  • C Colin Angus Mackay

                    I suspect this is where the exception was CAUGHT. Not where it was generated/thrown.

                    static void Main()
                    {
                    try
                    {
                    Application.Run(new MainForm());
                    }
                    catch(Exception e)
                    {
                    Debug.WriteLine(e.Message);
                    Debug.WriteLine(e.StackTrace);
                    }
                    }

                    Will write to the output the location that the error was generated. This will help with solving the problem. --Colin Mackay--

                    "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

                    H Offline
                    H Offline
                    Heath Stewart
                    wrote on last edited by
                    #9

                    Colin, note that putting a try-catch around Application.Run only works when an exception causes the application message pump to terminate. This is usually not the case. The try-catch should be as local to the problem as possible (like in the original poster's code to create the Word app and open the document). You can also handle the AppDomain.UnhandledException event.

                    -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                    C 1 Reply Last reply
                    0
                    • H Heath Stewart

                      Colin, note that putting a try-catch around Application.Run only works when an exception causes the application message pump to terminate. This is usually not the case. The try-catch should be as local to the problem as possible (like in the original poster's code to create the Word app and open the document). You can also handle the AppDomain.UnhandledException event.

                      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                      C Offline
                      C Offline
                      Colin Angus Mackay
                      wrote on last edited by
                      #10

                      Heath Stewart wrote: Colin, note that putting a try-catch around Application.Run only works when an exception causes the application message pump to terminate True, like happened here. I realise that the try...catch would be better placed else where but trying to help quickly I figured it was easiest to put round the Application.Run. --Colin Mackay--

                      "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

                      H 1 Reply Last reply
                      0
                      • C Colin Angus Mackay

                        Heath Stewart wrote: Colin, note that putting a try-catch around Application.Run only works when an exception causes the application message pump to terminate True, like happened here. I realise that the try...catch would be better placed else where but trying to help quickly I figured it was easiest to put round the Application.Run. --Colin Mackay--

                        "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

                        H Offline
                        H Offline
                        hazzem elrefai
                        wrote on last edited by
                        #11

                        iam so confised now,coz i can not run my application yet and i do not know what is the problem exactly.

                        C 1 Reply Last reply
                        0
                        • H hazzem elrefai

                          iam so confised now,coz i can not run my application yet and i do not know what is the problem exactly.

                          C Offline
                          C Offline
                          Colin Angus Mackay
                          wrote on last edited by
                          #12

                          Well, it looks like your code was copied from the documentation. So I don't see much difference between that and MSDN. Are you using a WordProject? --Colin Mackay--

                          "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

                          H 1 Reply Last reply
                          0
                          • C Colin Angus Mackay

                            Well, it looks like your code was copied from the documentation. So I don't see much difference between that and MSDN. Are you using a WordProject? --Colin Mackay--

                            "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

                            H Offline
                            H Offline
                            hazzem elrefai
                            wrote on last edited by
                            #13

                            i do not know what is word project exactly but if it is wizard in vs.net,then i do not use it and it doesn't there iam using vs.net2003 profissional thanx

                            C 1 Reply Last reply
                            0
                            • H hazzem elrefai

                              i do not know what is word project exactly but if it is wizard in vs.net,then i do not use it and it doesn't there iam using vs.net2003 profissional thanx

                              C Offline
                              C Offline
                              Colin Angus Mackay
                              wrote on last edited by
                              #14

                              I'm using VS2003 and Office 2003 (So it might be an office thing) Anyway - I've emailed you the skeleton of the WordProject - it might provide clues to help with your problem. (Its easy for me because it does all the hard work getting everything integrated - You may have to change the project properties because the startup command line may be different in your case) --Colin Mackay--

                              "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

                              H 1 Reply Last reply
                              0
                              • C Colin Angus Mackay

                                I'm using VS2003 and Office 2003 (So it might be an office thing) Anyway - I've emailed you the skeleton of the WordProject - it might provide clues to help with your problem. (Its easy for me because it does all the hard work getting everything integrated - You may have to change the project properties because the startup command line may be different in your case) --Colin Mackay--

                                "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

                                H Offline
                                H Offline
                                hazzem elrefai
                                wrote on last edited by
                                #15

                                thank u so so so much and sorry coz i have to go know and c u after little hours

                                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