Microsoft KB Archive/176242

= XL97: Access Violation or Page Fault Closing a Microsoft Excel Worksheet Object =

Article ID: 176242

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 97 Standard Edition

-



This article was previously published under Q176242





SYMPTOMS
When you activate a Microsoft Excel worksheet object and then click "Close & Return to ," where  is the name of the document that contains the Microsoft Excel worksheet object, you may receive an error message that is similar to one of the following.

Microsoft Windows 95
This program has performed an illegal operation and will be shut down. If the problem persists, contact the program vendor.

If you click Details, you may receive an error message similar to the following:

Excel caused an invalid page fault in module Excel.exe at 015f:3005a618.

Microsoft Windows NT
Dr. Watson for Windows NT

An application error has occurred and an application error log is being generated.

Excel.exe

Exception: access violation (0xc0000005), Address 0x3005a618.



CAUSE
This problem may occur if the following conditions are true:


 * You have created a Visual Basic for Applications macro with an Application event handler for the WorkbookBeforeClose event. -and-


 * You open two Excel worksheet objects that have been inserted into a document that has been created in another program (such as Microsoft Word). -and-


 * One of the Excel worksheet objects is linked to the other Excel worksheet object. -and-


 * You close one of the Excel worksheet objects.



STATUS
Microsoft has confirmed this to be a problem in Microsoft Excel 97 for Windows. This problem was corrected in Microsoft Office 97 Service Release 2 (SR-2).

For additional information about SR-2, please see the following article in the Microsoft Knowledge Base:

151261 OFF97: How to Obtain and Install MS Office 97 SR-2



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

Example of the Problem
To see an example of this problem, follow these steps.

Create the WorkbookBeforeClose Event Handler
 Start Excel. If you do not have a Personal Macro Workbook (Personal.xls), create one; otherwise, proceed to step 3 if you already have a Personal Macro Workbook. To create this workbook, follow these steps:

 On the Tools menu, point to Macro, and then click Record New Macro. Click Personal Macro Workbook in the Store Macro In list, and then click OK.</li> On the Tools menu, point to Macro, and then click Stop Recording.</li></ol> </li> Start the Visual Basic Editor (press ALT+F11).</li> Press CTRL+R to switch to the Project Explorer Window.</li> In the Project Explorer window, click to select VBAProject (PERSONAL.XLS).</li> On the Insert menu, click Class Module to insert a Class module.</li>  Type the following code into the class module: Public WithEvents App As Application

Private Sub App_WorkbookBeforeClose(ByVal Wb As Excel.Workbook, _      Cancel As Boolean)

MsgBox "App_WorkbookBeforeClose"

End Sub </li> In the Project Explorer window of Visual Basic Editor, double-click ThisWorkbook in the current project.</li>  Type the following code into the ThisWorkbook module sheet. Dim X As New Class1

Private Sub Workbook_Open

Set X.App = Application

End Sub </li> On the File menu, click "Close and Return to Microsoft Excel."</li> Click Exit on the File menu. Click Yes when you are prompted to save the changes in the Personal Macro Workbook.</li></ol>

Inserting Excel Objects into a Word Document
To insert the Excel objects, follow these steps:

<ol> Start Word.</li> On the Insert menu, click Object. Click Microsoft Excel Worksheet in the Object Type list, and then click OK.

An Excel worksheet object is inserted into your document.</li> Click the Word document to switch to Word.</li> On the Insert menu, click Object. Click Microsoft Excel Worksheet in the Object Type list, and then click OK.

An Excel worksheet object is inserted into your document.</li> Click the Word document to switch to Word.</li> Right-click the first embedded Excel object, point to Worksheet Object on the shortcut menu, and then click Open.</li> <li>Switch to Word.</li> <li>Right-click the second embedded Excel object, point to Worksheet Object on the shortcut menu, and then click Open.</li> <li> Type the following formula into cell A1 of the "Worksheet in Document1 2" workbook, and then press ENTER: ='[Worksheet in Document3]Sheet1'!$A$1 </li> <li>On the File menu, click "Close & Return to Document1."</li></ol>

You may receive an error message that is similar the messages described in the "Symptoms" section in this article.

Keywords: kbhotfixserver kbqfe kbbug kberrmsg kbfix KB176242

-

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

© Microsoft Corporation. All rights reserved.