Microsoft KB Archive/832121

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

Article ID: 832121

Article Last Modified on 3/30/2007

-

APPLIES TO


 * Microsoft Office Excel 2007
 * Microsoft Office Word 2007
 * Microsoft Office Excel 2003
 * Microsoft Office Word 2003

-



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 &quot;Applies to&quot; 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:

http://www.microsoft.com/downloads/details.aspx?FamilyId=24A557F7-EB06-4A2C-8F6C-2767B174126F

To create the Smart Document solution, follow these steps:  Start Microsoft Visual Basic 6.0. On the File menu, click New Project. In the New Project dialog box, select ActiveX DLL, and then click OK. Type SDCloseonInit for the Project Name.  In the Class Module window, add the following code: Implements ISmartDocument Dim spath As String

'Namespace constant Const cNAMESPACE As String = &quot;SDCloseonInit&quot;

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

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 = &quot;Word.Application.11&quot; 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 &quot;Solution error:&quot; & 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 = &quot;Textbox&quot; Case 2 ISmartDocument_SmartDocXmlTypeCaption = &quot;Click&quot; 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 = _ &quot;Enter your name:&quot; Case 101 ISmartDocument_ControlCaptionFromID = _ &quot;Test button&quot; 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  Office 2007

On the Project menu, add a reference to the following libraries, and then click OK: <ul> Microsoft Excel 12.0 Object Library</li> Microsoft Word 12.0 Object Library</li> Microsoft Smart Tags 2.0 Type Library</li></ul>

. Office 2003

On the Project menu, add a reference to the following libraries, and then click OK: <ul> Microsoft Excel 11.0 Object Library</li> Microsoft Word 11.0 Object Library</li> Microsoft Smart Tags 2.0 Type Library</li></ul>

Click OK.

</li> On the File menu, click Make SDCloseonInit.dll to build the Smart Document solution.</li></ol>

To create the Manifest file, follow these steps: <ol>  Start Notepad, and then paste the following code in the Notepad document: <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?> <manifest xmlns=&quot;http://schemas.microsoft.com/office/xmlexpansionpacks/2003&quot;> 1.1    <updateFrequency>20160</updateFrequency> SDCloseonInit <solutionID><CLSID of the Smart Document solution></solutionID> smartDocument <alias lcid=&quot;*&quot;>SDCloseonInit - VB6 solutionActionHandler 1.0            <filePath>SDCloseonInit.dll</filePath> <runFromServer>True</runFromServer> <CLSID><CLSID of the Smart Document solution></CLSID> <solutionID>schema</solutionID> schema <alias lcid=&quot;*&quot;>SDCloseonInit schema 1.0            <filePath>SDCloseonInit.xsd</filePath> </li> Start RegEdit.exe.</li> Expand the  hive, and then locate the SDCloseonInit.Class1 key.</li> Expand the SDCloseonInit.Class1 key, and then select the CLSID subkey.</li> 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.

</li> Save the file as SDCloseonInitManifest.xml. Close the SDCloseonInitManifest.xml file.</li></ol>

To create the Schema file, follow these steps: <ol>  Start Notepad, and then paste the following code in the Notepad document. <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns=&quot;SDCloseonInit&quot; targetNamespace=&quot;SDCloseonInit&quot; elementFormDefault=&quot;qualified&quot;>

<xsd:complexType name=&quot;exampleType&quot;> <xsd:all> <xsd:element name=&quot;textbox&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;commandbutton&quot; type=&quot;xsd:string&quot;/> </xsd:all> </xsd:complexType>

<xsd:element name=&quot;example&quot; type=&quot;exampleType&quot;/>

</xsd:schema> </li> Save the file as SDCloseonInit.xsd. Close the SDCloseonInit.xsd file.</li></ol>

To create the Excel 2003 file and to test the Smart Document, follow these steps: <ol> 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.</li> <li>Start Excel.</li> <li>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.

</li> <li>In the XML Expansion Packs dialog box, click Add.</li> <li>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?

</li> <li>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 &quot;Symptoms&quot; section.</li></ol>

Additional query words: XL2007 WD2007

Keywords: kbbug kbofficesmartdoc KB832121

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.