Your application may unexpectedly shut down when you close a document from the SmartDocument_Initialize event in Excel or in Word

BUG #: 424849 (OfficeNET)

Important This article contains information about modifying the registry. Before you modify the registry, make sure to back it up and make sure that you understand how to restore the registry if a problem occurs. For information about how to back up, restore, and edit the registry, click the following article number to view the article in the Microsoft Knowledge Base:
256986 Description of the Microsoft Windows Registry

Symptoms

When you run a command to close a Microsoft Office Excel 2007 or Microsoft Office Excel 2003 document from the SmartDocument_Initialize event of a Smart Document solution, you may receive the following error message:

Microsoft Office Excel 2007
Microsoft Office Excel has stopped working.
Microsoft Office Excel 2003
Microsoft Office Excel has encountered a problem and needs to close. We are sorry for the inconvenience.
When you run a command to close a Microsoft Office Word 2007 document or a Microsoft Office Word 2003 document from the SmartDocument_Initialize event of a Smart Document solution, you may receive the following error message:

Microsoft Office Word 2007
Microsoft Office Word has stopped working.
Microsoft Office Word 2003
Microsoft Office Word has encountered a problem and needs to close. We are sorry for the inconvenience.

Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section of this article.

More Information

Warning If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.

Steps to reproduce the problem

Note The following steps use information and files that are installed with the Microsoft Office 2003 Smart Document software development kit (SDK). For additional information about how to download and how to install the Office 2003 Smart Document SDK, visit the following Microsoft Web site:To create the Smart Document solution, follow these steps:
  1. Start Microsoft Visual Basic 6.0.
  2. On the
    File
    menu, click
    New Project.

  3. In the
    New Project
    dialog box, select
    ActiveX DLL, and then click
    OK.

  4. Type SDCloseonInit for the Project Name.

  5. In the Class Module window, add the following code:
    Implements ISmartDocument
    Dim spath As String

    'Namespace constant
    Const cNAMESPACE As String = "SDCloseonInit"

    'Element constants
    Const cTEXTBOX As String = cNAMESPACE & "#textbox"
    Const cBUTTON As String = cNAMESPACE & "#commandbutton"

    Const cTypes As Integer = 2
    Private Sub ISmartDocument_SmartDocInitialize(ByVal ApplicationName As String, ByVal Document As Object,
    ByVal SolutionPath As String, ByVal SolutionRegKeyRoot As String)
    spath = SolutionPath

    If ApplicationName = "Word.Application.11" Then
    Dim solutionDoc As Word.Document
    Set solutionDoc = Document
    solutionDoc.Close False 'This line causes the error.
    Else
    Dim solutionBook As Workbook
    Set solutionBook = Document
    solutionBook.Close False 'This line causes the error.
    End If

    On Error GoTo SDIERR
    Exit Sub
    SDIERR:
    MsgBox "Solution error:" & Err.Description
    Err.Clear
    Resume Next
    End Sub

    Private Property Get ISmartDocument_SmartDocXmlTypeCount() As Long

    ISmartDocument_SmartDocXmlTypeCount = cTypes

    End Property

    Private Property Get ISmartDocument_SmartDocXmlTypeName( _
    ByVal XMLTypeID As Long) As String

    Select Case XMLTypeID
    Case 1
    ISmartDocument_SmartDocXmlTypeName = cTEXTBOX
    Case 2
    ISmartDocument_SmartDocXmlTypeName = cBUTTON
    Case Else

    End Select

    End Property

    Private Property Get ISmartDocument_SmartDocXmlTypeCaption( _
    ByVal XMLTypeID As Long, ByVal LocaleID As Long) As String

    Select Case XMLTypeID
    Case 1
    ISmartDocument_SmartDocXmlTypeCaption = "Textbox"
    Case 2
    ISmartDocument_SmartDocXmlTypeCaption = "Click"
    Case Else

    End Select

    End Property

    Private Property Get ISmartDocument_ControlCount( _
    ByVal XMLTypeName As String) As Long

    Select Case XMLTypeName
    Case cTEXTBOX
    ISmartDocument_ControlCount = 1
    Case cBUTTON
    ISmartDocument_ControlCount = 1
    Case Else

    End Select

    End Property

    'The ControlID for the first control that you add is 1.
    'For additional information about how to specify the ControlID, see the ControlID reference
    'topic in the References section of this SDK.
    Private Property Get ISmartDocument_ControlID( _
    ByVal XMLTypeName As String, _
    ByVal ControlIndex As Long) As Long

    Select Case XMLTypeName
    Case cTEXTBOX
    ISmartDocument_ControlID = ControlIndex
    Case cBUTTON
    ISmartDocument_ControlID = ControlIndex + 100
    Case Else

    End Select

    End Property

    Private Property Get ISmartDocument_ControlNameFromID( _
    ByVal ControlID As Long) As String

    ISmartDocument_ControlNameFromID = cNAMESPACE & ControlID

    End Property

    Private Property Get ISmartDocument_ControlCaptionFromID( _
    ByVal ControlID As Long, ByVal ApplicationName As String, _
    ByVal LocaleID As Long, ByVal Text As String, _
    ByVal Xml As String, ByVal Target As Object) As String

    Select Case ControlID
    Case 1
    ISmartDocument_ControlCaptionFromID = _
    "Enter your name:"
    Case 101
    ISmartDocument_ControlCaptionFromID = _
    "Test button"
    Case Else

    End Select

    End Property

    Private Property Get ISmartDocument_ControlTypeFromID( _
    ByVal ControlID As Long, _
    ByVal ApplicationName As String, _
    ByVal LocaleID As Long) As SmartTagLib.C_TYPE

    Select Case ControlID
    Case 1
    ISmartDocument_ControlTypeFromID = C_TYPE_TEXTBOX
    Case 101
    ISmartDocument_ControlTypeFromID = C_TYPE_BUTTON
    Case Else

    End Select

    End Property

    Private Sub ISmartDocument_PopulateActiveXProps(ByVal ControlID As Long, ByVal ApplicationName As String,
    ByVal LocaleID As Long, ByVal Text As String, ByVal Xml As String, ByVal Target As Object,
    ByVal Props As SmartTagLib.ISmartDocProperties, ByVal ActiveXPropBag As SmartTagLib.ISmartDocProperties)

    End Sub

    Private Sub ISmartDocument_PopulateCheckbox(ByVal ControlID As Long, ByVal ApplicationName As String,
    ByVal LocaleID As Long, ByVal Text As String, ByVal Xml As String, ByVal Target As Object,
    ByVal Props As SmartTagLib.ISmartDocProperties, Checked As Boolean)

    End Sub

    Private Sub ISmartDocument_PopulateDocumentFragment(ByVal ControlID As Long, ByVal ApplicationName As String,
    ByVal LocaleID As Long, ByVal Text As String, ByVal Xml As String, ByVal Target As Object,
    ByVal Props As SmartTagLib.ISmartDocProperties, DocumentFragment As String)

    End Sub

    Private Sub ISmartDocument_PopulateHelpContent(ByVal ControlID As Long, ByVal ApplicationName As String,
    ByVal LocaleID As Long, ByVal Text As String, ByVal Xml As String, ByVal Target As Object,
    ByVal Props As SmartTagLib.ISmartDocProperties, Content As String)

    End Sub

    Private Sub ISmartDocument_PopulateImage(ByVal ControlID As Long, ByVal ApplicationName As String,
    ByVal LocaleID As Long, ByVal Text As String, ByVal Xml As String, ByVal Target As Object,
    ByVal Props As SmartTagLib.ISmartDocProperties, ImageSrc As String)

    End Sub

    Private Sub ISmartDocument_PopulateListOrComboContent(ByVal ControlID As Long,
    ByVal ApplicationName As String, ByVal LocaleID As Long, ByVal Text As String,
    ByVal Xml As String, ByVal Target As Object, ByVal Props As SmartTagLib.ISmartDocProperties,
    List() As String, count As Long, InitialSelected As Long)

    End Sub

    Private Sub ISmartDocument_PopulateOther(ByVal ControlID As Long, ByVal ApplicationName As String,
    ByVal LocaleID As Long, ByVal Text As String, ByVal Xml As String, ByVal Target As Object,
    ByVal Props As SmartTagLib.ISmartDocProperties)

    End Sub

    Private Sub ISmartDocument_PopulateRadioGroup(ByVal ControlID As Long, ByVal ApplicationName As String,
    ByVal LocaleID As Long, ByVal Text As String, ByVal Xml As String, ByVal Target As Object,
    ByVal Props As SmartTagLib.ISmartDocProperties, List() As String, count As Long, InitialSelected As Long)

    End Sub

    Private Sub ISmartDocument_PopulateTextboxContent( _
    ByVal ControlID As Long, ByVal ApplicationName As String, _
    ByVal LocaleID As Long, ByVal Text As String, _
    ByVal Xml As String, ByVal Target As Object, _
    ByVal Props As SmartTagLib.ISmartDocProperties, Value As String)

    End Sub

    Private Sub ISmartDocument_ImageClick(ByVal ControlID As Long, ByVal ApplicationName As String,
    ByVal Target As Object, ByVal Text As String, ByVal Xml As String, ByVal LocaleID As Long,
    ByVal XCoordinate As Long, ByVal YCoordinate As Long)

    End Sub

    Private Sub ISmartDocument_InvokeControl(ByVal ControlID As Long, ByVal ApplicationName As String,
    ByVal Target As Object, ByVal Text As String, ByVal Xml As String, ByVal LocaleID As Long)

    End Sub

    Private Sub ISmartDocument_OnCheckboxChange(ByVal ControlID As Long, ByVal Target As Object,
    ByVal Checked As Boolean)

    End Sub

    Private Sub ISmartDocument_OnListOrComboSelectChange(ByVal ControlID As Long, ByVal Target As Object,
    ByVal Selected As Long, ByVal Value As String)

    End Sub

    Private Sub ISmartDocument_OnRadioGroupSelectChange(ByVal ControlID As Long, ByVal Target As Object,
    ByVal Selected As Long, ByVal Value As String)

    End Sub

    Private Sub ISmartDocument_OnTextboxContentChange( _
    ByVal ControlID As Long, ByVal Target As Object, _
    ByVal Value As String)

    End Sub

    Private Sub ISmartDocument_OnPaneUpdateComplete(ByVal Document As Object)

    End Sub
  6. Office 2007
    On the
    Project
    menu, add a reference to the following libraries, and then click OK:
    • Microsoft Excel 12.0 Object Library
    • Microsoft Word 12.0 Object Library
    • Microsoft Smart Tags 2.0 Type Library
    .

    Office 2003
    On the
    Project
    menu, add a reference to the following libraries, and then click OK:
    • Microsoft Excel 11.0 Object Library
    • Microsoft Word 11.0 Object Library
    • Microsoft Smart Tags 2.0 Type Library
    Click
    OK.



  7. On the
    File
    menu, click
    Make SDCloseonInit.dll
    to build the Smart Document solution.
To create the Manifest file, follow these steps:

  1. Start Notepad, and then paste the following code in the Notepad document:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <manifest xmlns="http://schemas.microsoft.com/office/xmlexpansionpacks/2003">
    <version>1.1</version>
    <updateFrequency>20160</updateFrequency>
    <uri>SDCloseonInit</uri>
    <solution>
    <solutionID><CLSID of the Smart Document solution></solutionID>
    <type>smartDocument</type>
    <alias lcid="*">SDCloseonInit - VB6</alias>
    <file>
    <type>solutionActionHandler</type>
    <version>1.0</version>
    <filePath>SDCloseonInit.dll</filePath>
    <runFromServer>True</runFromServer>
    <CLSID><CLSID of the Smart Document solution></CLSID>
    <regsvr32/>
    </file>
    </solution>
    <solution>
    <solutionID>schema</solutionID>
    <type>schema</type>
    <alias lcid="*">SDCloseonInit</alias>
    <file>
    <type>schema</type>
    <version>1.0</version>
    <filePath>SDCloseonInit.xsd</filePath>
    </file>
    </solution>
    </manifest>
  2. Start RegEdit.exe.
  3. Expand the HKEY_CLASSES_ROOT hive, and then locate the SDCloseonInit.Class1 key.
  4. Expand the SDCloseonInit.Class1 key, and then select the CLSID subkey.
  5. Copy the GUID for the CLSID subkey. Replace the two occurrences of
    <CLSID of the Smart Document solution>
    in the code with the GUID of the assembly.

  6. Save the file as SDCloseonInitManifest.xml. Close the SDCloseonInitManifest.xml file.
To create the Schema file, follow these steps:

  1. Start Notepad, and then paste the following code in the Notepad document.
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="SDCloseonInit"
    targetNamespace="SDCloseonInit"
    elementFormDefault="qualified">

    <xsd:complexType name="exampleType">
    <xsd:all>
    <xsd:element name="textbox" type="xsd:string"/>
    <xsd:element name="commandbutton" type="xsd:string"/>
    </xsd:all>
    </xsd:complexType>

    <xsd:element name="example" type="exampleType"/>

    </xsd:schema>
  2. Save the file as SDCloseonInit.xsd. Close the SDCloseonInit.xsd file.
To create the Excel 2003 file and to test the Smart Document, follow these steps:
  1. Locate the DisableManifestSecurityCheck.reg file that is installed with the Office 2003 Smart Document SDK. Double-click DisableManifestSecurityCheck.reg to add the registry key that disables the manifest security check.
  2. Start Excel.
  3. In Excel 2007, click the Developer tab, and then click Expansion Packs. In Excel 2003 click
    XML on the
    Data
    menu, and then click XML Expansion Packs.


  4. In the
    XML Expansion Packs
    dialog box, click Add.

  5. Move to the location of the SDCloseonInitManifest.xml file that you previously created. Select the SDCloseonInitManifest.xml file, and then click
    Open.

    Click
    No if you receive the following message:

    XML expansion pack security has been disabled. This makes development of the solution easier but allows unsafe XML expansion pack components to run. Would you like to re-enable XML expansion pack security?
  6. In the Available XML expansion packs
    list, select SDCloseonInit - VB6, and then click Attach. Click OK to close the XML Expansion Packs dialog box.

    You may receive the Excel 2003 error message that is mentioned in the "Symptoms" section.
Propriedades

ID do Artigo: 832121 - Última Revisão: 6 de out de 2011 - Revisão: 1

Comentários