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.
-or-