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. Getting an Exception : (HRESULT: 0x800A140C ) while trying to close Word 2k10 Document

Getting an Exception : (HRESULT: 0x800A140C ) while trying to close Word 2k10 Document

Scheduled Pinned Locked Moved C#
com
8 Posts 6 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.
  • K Offline
    K Offline
    Kushagra Tiwari
    wrote on last edited by
    #1

    Hi all, I have tried to open an existing Word 2k10 document in mail merge format.

    private object tArg = true;
    private object fArg = false;
    private object wOriginalFormat = Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat;

    sourceDoc = word.Documents.Open(ref oSourceFile,//1The name of the document (paths are accepted).
    ref mArg,//2True to display the Convert File dialog box if the file isn't in Microsoft Word format.
    ref mArg,//3True to open the document as read-only.
    ref mArg,//4True to add the file name to the list of recently used files at the bottom of the File menu.
    ref mArg,//5The password for opening the document.
    ref mArg,//6The password for opening the template.
    ref mArg,//7Controls what happens if FileName is the name of an open document. True to discard any unsaved changes to the open document and reopen the file. False to activate the open document.
    ref mArg,//8The password for saving changes to the document.
    ref mArg,//9The password for saving changes to the template.
    ref wdOpenFormatAllWord,//10The file converter to be used to open the document. Can be one of the following WdOpenFormat constants
    ref fArg,//11The document encoding (code page or character set) to be used by Microsoft Word when you view the saved document.
    ref mArg,//12True if the document is opened in a visible window. The default value is True.
    ref mArg,//13Specifies whether to open the conflict file for a document with an offline conflict.
    ref mArg,//14True to repair the document to prevent document corruption.
    ref mArg,//15True to skip displaying the Encoding dialog box that Word displays if the text encoding cannot be recognized. The default value is False.
    ref mArg);//16Indicates the horizontal flow of text in a document. The default value is wdLeftToRight.

    a

    L M I K G 5 Replies Last reply
    0
    • K Kushagra Tiwari

      Hi all, I have tried to open an existing Word 2k10 document in mail merge format.

      private object tArg = true;
      private object fArg = false;
      private object wOriginalFormat = Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat;

      sourceDoc = word.Documents.Open(ref oSourceFile,//1The name of the document (paths are accepted).
      ref mArg,//2True to display the Convert File dialog box if the file isn't in Microsoft Word format.
      ref mArg,//3True to open the document as read-only.
      ref mArg,//4True to add the file name to the list of recently used files at the bottom of the File menu.
      ref mArg,//5The password for opening the document.
      ref mArg,//6The password for opening the template.
      ref mArg,//7Controls what happens if FileName is the name of an open document. True to discard any unsaved changes to the open document and reopen the file. False to activate the open document.
      ref mArg,//8The password for saving changes to the document.
      ref mArg,//9The password for saving changes to the template.
      ref wdOpenFormatAllWord,//10The file converter to be used to open the document. Can be one of the following WdOpenFormat constants
      ref fArg,//11The document encoding (code page or character set) to be used by Microsoft Word when you view the saved document.
      ref mArg,//12True if the document is opened in a visible window. The default value is True.
      ref mArg,//13Specifies whether to open the conflict file for a document with an offline conflict.
      ref mArg,//14True to repair the document to prevent document corruption.
      ref mArg,//15True to skip displaying the Encoding dialog box that Word displays if the text encoding cannot be recognized. The default value is False.
      ref mArg);//16Indicates the horizontal flow of text in a document. The default value is wdLeftToRight.

      a

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Googling your error code gives remarkably few hits, the most promising one is http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_26382757.html[^] which needs you to create a temporary account in order to read the "accepted solution". Not sure it will be any good though. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      1 Reply Last reply
      0
      • K Kushagra Tiwari

        Hi all, I have tried to open an existing Word 2k10 document in mail merge format.

        private object tArg = true;
        private object fArg = false;
        private object wOriginalFormat = Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat;

        sourceDoc = word.Documents.Open(ref oSourceFile,//1The name of the document (paths are accepted).
        ref mArg,//2True to display the Convert File dialog box if the file isn't in Microsoft Word format.
        ref mArg,//3True to open the document as read-only.
        ref mArg,//4True to add the file name to the list of recently used files at the bottom of the File menu.
        ref mArg,//5The password for opening the document.
        ref mArg,//6The password for opening the template.
        ref mArg,//7Controls what happens if FileName is the name of an open document. True to discard any unsaved changes to the open document and reopen the file. False to activate the open document.
        ref mArg,//8The password for saving changes to the document.
        ref mArg,//9The password for saving changes to the template.
        ref wdOpenFormatAllWord,//10The file converter to be used to open the document. Can be one of the following WdOpenFormat constants
        ref fArg,//11The document encoding (code page or character set) to be used by Microsoft Word when you view the saved document.
        ref mArg,//12True if the document is opened in a visible window. The default value is True.
        ref mArg,//13Specifies whether to open the conflict file for a document with an offline conflict.
        ref mArg,//14True to repair the document to prevent document corruption.
        ref mArg,//15True to skip displaying the Encoding dialog box that Word displays if the text encoding cannot be recognized. The default value is False.
        ref mArg);//16Indicates the horizontal flow of text in a document. The default value is wdLeftToRight.

        a

        M Offline
        M Offline
        Manfred Rudolf Bihy
        wrote on last edited by
        #3

        Hello Kushagra, what is the value ofthe variable mArg. It's being used in some places where a boolean is expected, but also as the last parameter where no boolean is expected. Parameter 11 has to do with encoding (as far as the comments go at least) but it's passed a boolean (fArg). Are your sure all the parameters are of the proper type and have a meaningfull value? Supplying a wrong parameter might still allow opening the document, but a subsequent save could fail. Best Regards, Manfred

        K 1 Reply Last reply
        0
        • M Manfred Rudolf Bihy

          Hello Kushagra, what is the value ofthe variable mArg. It's being used in some places where a boolean is expected, but also as the last parameter where no boolean is expected. Parameter 11 has to do with encoding (as far as the comments go at least) but it's passed a boolean (fArg). Are your sure all the parameters are of the proper type and have a meaningfull value? Supplying a wrong parameter might still allow opening the document, but a subsequent save could fail. Best Regards, Manfred

          K Offline
          K Offline
          Kushagra Tiwari
          wrote on last edited by
          #4

          ManfredRBihy wrote:

          what is the value ofthe variable mArg. It's being used in some places where a boolean is expected, but also as the last parameter where no boolean is expected.

          mArg is nothing but NULL which specifies missing value to let the function decide its own default value. I will look for replacing the right parameters .. meanwhile if you find some good solution on this .. please let me know. -Kushagra

          1 Reply Last reply
          0
          • K Kushagra Tiwari

            Hi all, I have tried to open an existing Word 2k10 document in mail merge format.

            private object tArg = true;
            private object fArg = false;
            private object wOriginalFormat = Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat;

            sourceDoc = word.Documents.Open(ref oSourceFile,//1The name of the document (paths are accepted).
            ref mArg,//2True to display the Convert File dialog box if the file isn't in Microsoft Word format.
            ref mArg,//3True to open the document as read-only.
            ref mArg,//4True to add the file name to the list of recently used files at the bottom of the File menu.
            ref mArg,//5The password for opening the document.
            ref mArg,//6The password for opening the template.
            ref mArg,//7Controls what happens if FileName is the name of an open document. True to discard any unsaved changes to the open document and reopen the file. False to activate the open document.
            ref mArg,//8The password for saving changes to the document.
            ref mArg,//9The password for saving changes to the template.
            ref wdOpenFormatAllWord,//10The file converter to be used to open the document. Can be one of the following WdOpenFormat constants
            ref fArg,//11The document encoding (code page or character set) to be used by Microsoft Word when you view the saved document.
            ref mArg,//12True if the document is opened in a visible window. The default value is True.
            ref mArg,//13Specifies whether to open the conflict file for a document with an offline conflict.
            ref mArg,//14True to repair the document to prevent document corruption.
            ref mArg,//15True to skip displaying the Encoding dialog box that Word displays if the text encoding cannot be recognized. The default value is False.
            ref mArg);//16Indicates the horizontal flow of text in a document. The default value is wdLeftToRight.

            a

            I Offline
            I Offline
            Ian Shlasko
            wrote on last edited by
            #5

            I haven't worked with the Word Interop, but I've done quite a bit with Excel Interop, which I would guess is similar... Instead of using dummy variables for parameters you don't want, use "Type.Missing" instead. For example, here's a line from one of my production systems that saves a file in Excel:

            Ref.SaveAs(outputFile, -4143, Type.Missing, Type.Missing, Type.Missing,
            Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
            Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

            "Ref" points to a Microsoft.Office.Interop.Excel.Workbook, outputFile is just a plain string variable. You shouldn't need to use dummy variables and "ref" keywords for everything.

            Proud to have finally moved to the A-Ark. Which one are you in?
            Author of the Guardians Saga (Sci-Fi/Fantasy novels)

            1 Reply Last reply
            0
            • K Kushagra Tiwari

              Hi all, I have tried to open an existing Word 2k10 document in mail merge format.

              private object tArg = true;
              private object fArg = false;
              private object wOriginalFormat = Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat;

              sourceDoc = word.Documents.Open(ref oSourceFile,//1The name of the document (paths are accepted).
              ref mArg,//2True to display the Convert File dialog box if the file isn't in Microsoft Word format.
              ref mArg,//3True to open the document as read-only.
              ref mArg,//4True to add the file name to the list of recently used files at the bottom of the File menu.
              ref mArg,//5The password for opening the document.
              ref mArg,//6The password for opening the template.
              ref mArg,//7Controls what happens if FileName is the name of an open document. True to discard any unsaved changes to the open document and reopen the file. False to activate the open document.
              ref mArg,//8The password for saving changes to the document.
              ref mArg,//9The password for saving changes to the template.
              ref wdOpenFormatAllWord,//10The file converter to be used to open the document. Can be one of the following WdOpenFormat constants
              ref fArg,//11The document encoding (code page or character set) to be used by Microsoft Word when you view the saved document.
              ref mArg,//12True if the document is opened in a visible window. The default value is True.
              ref mArg,//13Specifies whether to open the conflict file for a document with an offline conflict.
              ref mArg,//14True to repair the document to prevent document corruption.
              ref mArg,//15True to skip displaying the Encoding dialog box that Word displays if the text encoding cannot be recognized. The default value is False.
              ref mArg);//16Indicates the horizontal flow of text in a document. The default value is wdLeftToRight.

              a

              K Offline
              K Offline
              Kushagra Tiwari
              wrote on last edited by
              #6

              I finally got this sorted ... Looks there is some issue with Save() api of WOrd 2010 where its not able to decide which format to save the document in ... I used SaveAs() instead and then closed the Document... which worked wonders in my case.. -Kushagra

              G 1 Reply Last reply
              0
              • K Kushagra Tiwari

                I finally got this sorted ... Looks there is some issue with Save() api of WOrd 2010 where its not able to decide which format to save the document in ... I used SaveAs() instead and then closed the Document... which worked wonders in my case.. -Kushagra

                G Offline
                G Offline
                GuzmanJ
                wrote on last edited by
                #7

                Apparently this issue occurs because the Compatibility Mode feature in Office 2010 (Word, Excel, etc.) has been turned off. I guess there are two ways you can fix this. Turn the Compatibility Mode feature back on or like the previous post mentions use the SaveAs() method instead. Using the SaveAs() method fixed the issue for me: Microsoft.Office.Interop.Word._Document msWord = new Document(); object filename = "C:\\SomeWordFile.doc"; // Open the document. Perform operations on the msWord object. // ... // ... // When it comes to close the document do something like this: object fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument; object missing = System.Reflection.Missing.Value; object notTrue = false; msWord.SaveAs(ref filename, ref fileFormat, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); msWord.Close(ref notTrue, ref missing, ref missing); Hope this helps.

                1 Reply Last reply
                0
                • K Kushagra Tiwari

                  Hi all, I have tried to open an existing Word 2k10 document in mail merge format.

                  private object tArg = true;
                  private object fArg = false;
                  private object wOriginalFormat = Microsoft.Office.Interop.Word.WdOriginalFormat.wdOriginalDocumentFormat;

                  sourceDoc = word.Documents.Open(ref oSourceFile,//1The name of the document (paths are accepted).
                  ref mArg,//2True to display the Convert File dialog box if the file isn't in Microsoft Word format.
                  ref mArg,//3True to open the document as read-only.
                  ref mArg,//4True to add the file name to the list of recently used files at the bottom of the File menu.
                  ref mArg,//5The password for opening the document.
                  ref mArg,//6The password for opening the template.
                  ref mArg,//7Controls what happens if FileName is the name of an open document. True to discard any unsaved changes to the open document and reopen the file. False to activate the open document.
                  ref mArg,//8The password for saving changes to the document.
                  ref mArg,//9The password for saving changes to the template.
                  ref wdOpenFormatAllWord,//10The file converter to be used to open the document. Can be one of the following WdOpenFormat constants
                  ref fArg,//11The document encoding (code page or character set) to be used by Microsoft Word when you view the saved document.
                  ref mArg,//12True if the document is opened in a visible window. The default value is True.
                  ref mArg,//13Specifies whether to open the conflict file for a document with an offline conflict.
                  ref mArg,//14True to repair the document to prevent document corruption.
                  ref mArg,//15True to skip displaying the Encoding dialog box that Word displays if the text encoding cannot be recognized. The default value is False.
                  ref mArg);//16Indicates the horizontal flow of text in a document. The default value is wdLeftToRight.

                  a

                  G Offline
                  G Offline
                  gmr_evgen
                  wrote on last edited by
                  #8

                  Just use *.docx instead *.doc for the name of your document and that is it.

                  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