none
Word automation problem when preview handler is in use RRS feed

  • Question

  • I'm experiencing a problem with opening Word document through automation when Windows Explorer is using the Word preview handler.

    Steps to reproduce the problem...

    1. Open Word (WINWORD.EXE will appear in task manager)

    2. In Windows Explorer (on Windows 7), use the preview pane to preview any Word document.  (The preview handler will use the existing WINWORD.EXE process).

    3. Create an application that runs the following code...

    Dim appWord As Microsoft.Office.Interop.Word.Application
    Try
        appWord = GetObject(, "Word.Application")
    Catch ex As System.Exception
        appWord = CreateObject("Word.Application")
    End Try
    
    Dim docDocument As Microsoft.Office.Interop.Word.Document
    docDocument = appWord.Documents.Open("C:\somefile.docx")

    Because Word is already running, the GetObject line will succeed, but the .Open statement will fail because the preview handler seems to change the active Word instance so that it now has restricted functionality.  The following error is returned...

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

    Is there any way to test for this restricted functionality?  I don't want to create a new instance of Word every time.

    • Edited by wclarke Thursday, January 24, 2013 4:34 PM
    Thursday, January 24, 2013 3:17 PM

Answers

  • Thank you for your response. 

    I had already seen the page you linked and Cindy's suggestion.  However, if I understand correctly, this suggestion will force a new instance of Word each time I open a document through automation.  This is what I want to avoid. Creating a new instance of Word for every document I open through automation is much slower, and uses more resources on the PC.

    This is why I am attempting to use GetObject first.  Only if GetObject fails (i.e. Word isn't already running) will I call CreateObject.  However, if GetObject returns the same Word instance that the preview handler is using, I get the error mentioned above when using Documents.Open.  I just want to detect if the instance returned by GetObject is being used by the preview handler, so that I can then use CreateObject instead.  I don't want to use CreateObject every time.

    This problem doesn't occur with equivalent code for Excel or PowerPoint and their preview handlers.  Only Word seems to have a problem.

    I'll try trapping the error on the Document.Open line, and use CreateObject if it fails with the specific error above.  Not ideal though.

    Friday, January 25, 2013 9:35 AM

All replies

  • Hi Wclarke,

    Thank you for posting in the MSDN Forum.

    I think you're having the same issue with the customer on this page.

    You can take Cindy's suggestion, try the solution on KB 188546.

    Use one of the following to work around this problem:

    • Before you create your Word object, first create a temporary Word object. After you create your object, close the temporary object. This causes Word to act properly when you control it through Automation (that is, if a user interactively starts Word, a new instance of Word is opened for the user). The automation instance remains hidden and separate. See the Steps to Reproduce Behavior section for an example of this workaround.
    • Make the Word object visible immediately after using the CreateObject function. This workaround is only for Microsoft Word 97. For example:
    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, January 25, 2013 7:23 AM
    Moderator
  • Thank you for your response. 

    I had already seen the page you linked and Cindy's suggestion.  However, if I understand correctly, this suggestion will force a new instance of Word each time I open a document through automation.  This is what I want to avoid. Creating a new instance of Word for every document I open through automation is much slower, and uses more resources on the PC.

    This is why I am attempting to use GetObject first.  Only if GetObject fails (i.e. Word isn't already running) will I call CreateObject.  However, if GetObject returns the same Word instance that the preview handler is using, I get the error mentioned above when using Documents.Open.  I just want to detect if the instance returned by GetObject is being used by the preview handler, so that I can then use CreateObject instead.  I don't want to use CreateObject every time.

    This problem doesn't occur with equivalent code for Excel or PowerPoint and their preview handlers.  Only Word seems to have a problem.

    I'll try trapping the error on the Document.Open line, and use CreateObject if it fails with the specific error above.  Not ideal though.

    Friday, January 25, 2013 9:35 AM