The Close event does not fire in a Word template code extension in Visual Studio Tools for the Office System (823998)



The information in this article applies to:

  • Microsoft Office Word 2003
  • Microsoft Visual Studio Tools for the Microsoft Office System version 2003

SYMPTOMS

You can create a Microsoft Office Word 2003 template that uses a managed code extension. You can create the managed code extension by using Microsoft Visual Studio Tools for the Microsoft Office System. When you attach the Word 2003 template to another document and then you close that document, the Close event in the managed code extension does not fire.

STATUS

This behavior is a limitation of the managed code extensions for Word 2003 templates.

MORE INFORMATION

When you open the template in Word 2003 and then you close the template in Word 2003, the Close event in the managed code extension fires. However, if you attach this template to another Word 2003 document and then you close that document, the Close event does not fire.

Steps to reproduce the problem

  1. Start Microsoft Visual Studio .NET 2003.
  2. On the File menu, point to New, and then click Project.
  3. In the Project Types list, expand Microsoft Office System Projects, and then click Visual Basic Projects.
  4. In the Templates list, click Word Template.
  5. Name the new project WordTemplateTest, and then click OK.

    The Microsoft Office Project Wizard appears.
  6. In the Microsoft Office Project Wizard, click Finish.
  7. In the ThisDocument.vb module, replace the existing ThisDocument_Close procedure with a version that displays a message box, as follows:
    Private Sub ThisDocument_Close() Handles ThisDocument.Close
            MessageBox.Show("This is the Close event.")
            ' Make sure that Close is not called two times.
            designModeClose = False
    End Sub
  8. On the Build menu, click Build Solution.
  9. On the Debug menu, click Start.

    Word 2003 starts with the solution.
  10. Close Word 2003.

    The Close event fires.
  11. Click OK to dismiss the message box.
  12. Start Word 2003.

    By default, a blank document is created.
  13. On the Tools menu, click Templates and Add-Ins.
  14. Click Attach, and then locate the WordTemplateTest.dot file.
  15. Click OK to close the Templates and Add-Ins dialog box.
  16. Close Word 2003.

    You are prompted to save the changes to the new document.
  17. Click No.

    The Close event from the template does not fire.

Modification Type:MinorLast Reviewed:2/3/2006
Keywords:kbprb KB823998 kbAudDeveloper