none
MS Word Application.Documents.Open throws exception in preview handler RRS feed

  • Question

  • Hi All,

    I'm writing MS Word 2010 .NET Addin.

    Loading a .docx file using Word the addin load and everything works just fine.

    When previewing the same file in Windows 7 peview handler I got an exception when trying: Application.Documents.Open

    It says: The Open method or property is not available because permission for this document is currently restricted.

    Any idea?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, July 20, 2011 2:41 PM

Answers

  • Hi Gao,

    I just saw your answer for my issue, thanks.

    Yes I know that the plugin is loaded, but I'm not getting any message like posted here.

    I'm working with Win 7 + Word 2010.

    The problem is, how can I get a referene to current Document loaded in the preview handle inside the loaded-plugin?

    Hi Tomer,

    Thanks for your update.

    I try to retrieve the document loaded in preview pane by using Marshal.GetActiveObject method. There is no problem to get the Word application instance, however, when I try to iterate over all the documents in the Word application, I find there is no document open in the application. You can confirm this from the code below:

     

     static void Main(string[] args)
      {
       Word.Application oWord = null;
       try
       {
        oWord = Marshal.GetActiveObject("Word.Application") as Word.Application;
       }
       catch (System.Runtime.InteropServices.COMException ex)
       {
        Console.WriteLine(
         String.Format("Excel application was not running: {0}",
         ex.Message));
        return;
       }
    
       if (oWord != null)
       {  
        foreach (Word.Document doc in oWord.Documents)
        {
         Console.WriteLine("An open document: " + doc.FullName);
        }  
       }
      }
    

    For more information about GetActiveObject method, please refer to:

    http://blogs.msdn.com/b/eric_carter/archive/2009/03/12/attaching-to-an-already-running-office-application-from-your-application-using-getactiveobject-or-bindtomoniker.aspx


    This is console application. Open a Word document in preview pane, you will the Word process added in task manager. Then you run the console application.

    So you see, the document loaded in preview pane doesn't open in Word application. I guess the document is available by using some Windows Preview pane APIs, but I'm not sure as I haven't found something similar in MSDN. I'll consult some experts who are familiar with Windows and I'll info you as soon as I get some valuable suggestion.

    Thanks for your understanding.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Tuesday, August 2, 2011 4:03 AM
    Moderator

All replies

  • Hi Tomer,

     Thanks for your post. 

    Do you know that if you preview a document in Windows Explorer, Windows will automatically launch a Word process and your add will also get loaded? So if you try to open a document in your add-in, and then open the same document in another Word process, you will get a notification like:

    I think the issue your encountered is similar with what I said previous. If you can provide more details about what your add-in supposed to do, we can troubleshoot this more accurately. 

    I look forward to hearing of you.



    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, July 21, 2011 8:45 AM
    Moderator
  • Hi Tomer,

    Any update on this issue?


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, July 28, 2011 3:25 AM
    Moderator
  • Hi Gao,

    I just saw your answer for my issue, thanks.

    Yes I know that the plugin is loaded, but I'm not getting any message like posted here.

    I'm working with Win 7 + Word 2010.

    The problem is, how can I get a referene to current Document loaded in the preview handle inside the loaded-plugin?

    Monday, August 1, 2011 7:12 PM
  • Hi Gao,

    I just saw your answer for my issue, thanks.

    Yes I know that the plugin is loaded, but I'm not getting any message like posted here.

    I'm working with Win 7 + Word 2010.

    The problem is, how can I get a referene to current Document loaded in the preview handle inside the loaded-plugin?

    Hi Tomer,

    Thanks for your update.

    I try to retrieve the document loaded in preview pane by using Marshal.GetActiveObject method. There is no problem to get the Word application instance, however, when I try to iterate over all the documents in the Word application, I find there is no document open in the application. You can confirm this from the code below:

     

     static void Main(string[] args)
      {
       Word.Application oWord = null;
       try
       {
        oWord = Marshal.GetActiveObject("Word.Application") as Word.Application;
       }
       catch (System.Runtime.InteropServices.COMException ex)
       {
        Console.WriteLine(
         String.Format("Excel application was not running: {0}",
         ex.Message));
        return;
       }
    
       if (oWord != null)
       {  
        foreach (Word.Document doc in oWord.Documents)
        {
         Console.WriteLine("An open document: " + doc.FullName);
        }  
       }
      }
    

    For more information about GetActiveObject method, please refer to:

    http://blogs.msdn.com/b/eric_carter/archive/2009/03/12/attaching-to-an-already-running-office-application-from-your-application-using-getactiveobject-or-bindtomoniker.aspx


    This is console application. Open a Word document in preview pane, you will the Word process added in task manager. Then you run the console application.

    So you see, the document loaded in preview pane doesn't open in Word application. I guess the document is available by using some Windows Preview pane APIs, but I'm not sure as I haven't found something similar in MSDN. I'll consult some experts who are familiar with Windows and I'll info you as soon as I get some valuable suggestion.

    Thanks for your understanding.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Tuesday, August 2, 2011 4:03 AM
    Moderator
  • Thanks for cheking. This is exactly the problem I've talked about. More than that, the document is not accessible even from the add-in itself.
    Monday, August 8, 2011 6:18 PM