Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: Invalid Page Fault When Using Macro to Close Workbook


View products that this article applies to.

This article was previously published under Q231129

↑ Back to the top


Symptoms

When you click a control from the Forms toolbar (such as a Button) to run a Microsoft Visual Basic for Applications macro, and that macro uses the Close method, you may receive the following error message:
This program has performed an illegal operation and will be shut down.
If you click Details, you receive an error message similar to the following:
Excel caused an invalid page fault in module Excel.exe at 015f:300e7e53.

↑ Back to the top


Cause

This problem occurs when the following conditions are true:
  • Your workbook contains both ActiveX controls and controls created from the Forms toolbar.

    -and-
  • You first click an ActiveX control.

    -and-
  • Without selecting anything else, you then click a Forms control.

    -and-
  • The Forms control runs a macro that closes the workbook.

↑ Back to the top


Workaround

To close the active workbook without receiving the error message, use either of the following methods.

Method 1: Use an ActiveX Control Instead of a Forms Control

Instead of running your macro with a control from the Forms toolbar, consider using an ActiveX control instead. For example, if you currently use a Button control from the Forms toolbar, use a CommandButton control (which is an ActiveX control) from the Control Toolbox instead.

To attach your current code to the Click event of the ActiveX control, double-click the command button. In the CommandButton1_Click event procedure, copy your code from the Forms button.

Method 2: Select a Cell

Select a cell on the worksheet before you click the Forms control that runs your macro. This removes the focus from the ActiveX control, allowing the workbook to close properly. You can either select a cell using your mouse or use a macro assigned to the ActiveX control's Click event to select a specified cell for you.

To select a cell in a macro, add a statement similar to either of the following in the Click event procedure of your ActiveX control.
ActiveCell.Select
				
-or-
Range("A1").Select
				

↑ Back to the top


Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


Keywords: KB231129, kbpending, kbbug, kberrmsg

↑ Back to the top

Article Info
Article ID : 231129
Revision : 3
Created on : 9/25/2003
Published on : 9/25/2003
Exists online : False
Views : 225