none
Deleting ActiveX Controls from document having Document_Open() Sub results in Word-crash next time doc is opened RRS feed

  • Question

    1. Create new Word document.
    2. Type some text.
    3. Add an ActiveX CheckBox.
    4. Open VBA script editor (Alt-F11).
    5. Double-click on ThisDocument.
    6. Add
      Private Sub Document_Open()
          Debug.Print "Hello"
      End Sub
    7. Save document as .dot (or .dotm) then close it.
    8. Double-click on the template in Explorer.
    9. Select all text (Ctrl-A) and delete (should remove everything including CheckBox).
    10. Save and close document.
    11. Open document.

    Now all hell breaks loose (Word can't open the document).

    At least it does for me. Word 2003 or Word 2010, same...

     

    This is somewhat related to the "Can't exit design mode because Control ... can not be created" message.

    This is the message we get when opening a Word document in our real-life application based on Oracles Siebel CRM.

     

    Stein-Tore Erdal

     

     

     


    • Edited by s.t.e Thursday, December 1, 2011 2:58 PM
    Thursday, December 1, 2011 2:22 PM

Answers

  • Hi Cindy,

    Thanks for the effort.

    I've tried closing the Word instance after step 7 and 10. Still in step 11 (double-clicking on file in Explorer) Word (2010) will start, take some time, close. Next time I'm asked if I want to start Word in safe mode.

    Now testing with Word 2010 14.0.6024.1000 SP1 MSO 14.0.6106.5005 (but seems to be the same without SP1 and with Word 2003...)

    It seems like it will be gone again if one simply insert an ActiveX control again, does not need to have same name, nor same type (haven't tested this extensively).

     

    Anyhow, our workaround ended up being that we replaced

    Private Sub Document_Open()
        Debug.Print "Hello"
    End Sub

    with

    Public Sub AutoOpen()
        Debug.Print "Hello"
    End Sub


    In our situation this does the trick as it seems the bug does not manifest itself when using AutoOpen combined with removed ActiveX controls.

    Anyone else considering using AutoOpen() instead of Document_Open() should check carefully that they are functionally equivalent and that AutoOpen will actually run in the situations you expect (this depends on how the instance of Word is created...).

    Stein-Tore

    Monday, December 12, 2011 11:15 AM

All replies

  • Hi Stein-Tore

    I can confirm the behavior in Word 2007, but I have no explanation.

    FWIW after Word crashes it's able to recover itself and the document. After that, the document opens normally.


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Mike_HelpYou Monday, December 5, 2011 5:07 AM
    Thursday, December 1, 2011 6:17 PM
    Moderator
  • Dear Stein-Tore and Cindy,
    I couldn't reproduce the problem in Word 2010. In step 10, Save and close document. I can't save and close the document. It always prompt the SaveAs dialog. Could you guide me more details about this? Why does the template file can't be modified and save?
    Regards

    Be happy.
    Monday, December 5, 2011 5:07 AM
  • Hi Mike

    Of course, you need to use Save As in order to save the document...


    Cindy Meister, VSTO/Word MVP
    Monday, December 5, 2011 7:33 AM
    Moderator
  • Hi Stein-Tore

    I've passed this problem along and it's logged in the Word team's bug database. But in the process, someone made a comment that, if the Word session is closed the problem won't occur at all.

    In a "real-world" situation, where you'd be distributing the template, there should therefore not be any problems.

    To the question of "why", my best guess would be that there may be a "temp" or "scratch" file around that hasn't been properly released when the template file is closed. Ending the Word session would take care of that. As a matter of fact, when you create ActiveX controls (and work with graphics) temporary files are generated in the Temp folder and it may have something to do with those since the problem appears to originate with the ActiveX control.


    Cindy Meister, VSTO/Word MVP
    Monday, December 5, 2011 7:37 AM
    Moderator
  • Hi Cindy,

    Thanks for the effort.

    I've tried closing the Word instance after step 7 and 10. Still in step 11 (double-clicking on file in Explorer) Word (2010) will start, take some time, close. Next time I'm asked if I want to start Word in safe mode.

    Now testing with Word 2010 14.0.6024.1000 SP1 MSO 14.0.6106.5005 (but seems to be the same without SP1 and with Word 2003...)

    It seems like it will be gone again if one simply insert an ActiveX control again, does not need to have same name, nor same type (haven't tested this extensively).

     

    Anyhow, our workaround ended up being that we replaced

    Private Sub Document_Open()
        Debug.Print "Hello"
    End Sub

    with

    Public Sub AutoOpen()
        Debug.Print "Hello"
    End Sub


    In our situation this does the trick as it seems the bug does not manifest itself when using AutoOpen combined with removed ActiveX controls.

    Anyone else considering using AutoOpen() instead of Document_Open() should check carefully that they are functionally equivalent and that AutoOpen will actually run in the situations you expect (this depends on how the instance of Word is created...).

    Stein-Tore

    Monday, December 12, 2011 11:15 AM
  • Hi Stein-Tore

    Thanks for posting the workaround. The two "Open events" fire at different times (I can't recall which is first) and that may make the important difference.


    Cindy Meister, VSTO/Word MVP
    Monday, December 12, 2011 11:36 AM
    Moderator