none
How to handle "Could not open macro storage." for Word 2013 in C# using File SetAttributes. RRS feed

  • Question

  • How to handle "Could not open macro storage." for Word 2013 in C# using File SetAttributes.

    I had tried 

    File.SetAttributes(fileName, FileAttributes.Normal);

    I am unable to load  documents   like protectedView Word documents or asking for Word documents like enabling editing docs .

    Error while opening doc :  [Add] | Microsoft Word.frmCompare.Add:  | Could not open macro storage.  |  System.Runtime.InteropServices.COMException (0x800A175D)

    At Line: document = wd.Documents.Add(ref fileName, ref missing, ref missing, false/true(both cases));

    Any suggestions..


    R L Kiran

    Thursday, June 21, 2018 8:43 AM

All replies

  • Hello Kiran Reddi,

    Why do you use the SetAttributes? Is the file a document template document?

    If you do not use the SetAttributes and create document based on the template directly, will you get the error?

    After using SetAttributes, what's the result if you try to click the template to create a document manually?

    Will it be related to specific template document or all the template documents?

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 22, 2018 3:08 AM
  • Hi Terry Xu,

      Thanks for reply back,

       Here is the below code I am using for collapse ribbon functionality for the word documents working fine except Protected view documents,how to handle that..

    Below code :

    Word.Application wd = new Word.Application();
     object fileName = @"C:\ANY_SAMPLE_ProtectedViewDocument.doc";
     object missing = System.Reflection.Missing.Value;
                    wd.Visible = true;
                    Word.Document document=new Word.Document();
    document = wd.Documents.Add(ref fileName,ref missing, ref missing, true);
    
     document.Activate();
                    Microsoft.Office.Core.CommandBar cmdbarRibbon = wd.CommandBars["Ribbon"];
                    int theHeight = cmdbarRibbon.Height;
                    wd.CommandBars.ExecuteMso("HideRibbon");
                    if (cmdbarRibbon.Height > theHeight) // It was hidden so try minimize
                    {
                        theHeight = cmdbarRibbon.Height;
    
                        wd.CommandBars.ExecuteMso("MinimizeRibbon");
    
                    }
                    else // it is now hidden, so revert then minimize
                    {
                        wd.CommandBars.ExecuteMso("HideRibbon");
                        wd.CommandBars.ExecuteMso("MinimizeRibbon");//commented
    
                        if (cmdbarRibbon.Height > theHeight) // It was already minimized so revert
                        {
                            wd.CommandBars.ExecuteMso("MinimizeRibbon");
                            //wd.CommandBars.ExecuteMso("MinimizeRibbon");//added
                        }
                    }
                    Console.ReadKey();
    //document.Close();

    For Example document used :any  Protected view document.FYI

    Facing Error like below

    NOTE : ONLY for Protected view documents only Iam facing below error ,remaining case it works fine.

    Error :  Could not open macro storage.  |  System.Runtime.InteropServices.COMException (0x800A175D)

    NOTE :For handling above error I had used , File.SetAttributes(fileName, FileAttributes.Normal);

    to set file normal mode.



    R L Kiran



    • Edited by Kiran Reddi Friday, June 22, 2018 8:24 AM spell mistake
    Friday, June 22, 2018 8:22 AM
  • It got Fixed , Thanks

    R L Kiran

    Friday, June 22, 2018 1:08 PM
  • Hello Kiran Reddi,

    I'm glad to hear that your issue has been resolved. I would suggest you mark any helpful reply or your reply as answer which is the correct way to close the thread. If you have any other issue, please feel free to post threads to let us know.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 25, 2018 1:25 AM
  • Can you please share the answer. I am also facing the same issue.
    Tuesday, October 30, 2018 7:27 AM