Before Close Problem - Simple

stumped

New Member
Joined
Jan 13, 2002
Messages
9
I am doing something wrong. I want to clear two forms and then save the workbook upon the user attempting to close the workbook.
I keep getting an error message:Event Procedure declaration doesn't match description of event having the same name. What am I doing wrong?

Private Sub Workbook_BeforeClose()

'This macro clears the supplemental form
Application.ScreenUpdating = False
Sheets("supplemental").Select
Range("h4").Select
ActiveCell.Clear
Range("C14").Select
ActiveCell.FormulaR1C1 = ""
Range("C16").Select
ActiveCell.FormulaR1C1 = ""
Application.ScreenUpdating = True

'This macro clears the worksheet form
Sheets("worksheet").Select
Range("I4").Select
ActiveCell.FormulaR1C1 = ""
Range("E7").Select
ActiveCell.FormulaR1C1 = ""
Range("E8").Select
ActiveCell.FormulaR1C1 = ""
Range("E9").Select
ActiveCell.FormulaR1C1 = ""
Range("f7").Select
ActiveCell.Clear
Range("e12").Select
ActiveCell.Clear
Range("e15").Select
ActiveCell.Clear
Range("F19").Select
ActiveCell.FormulaR1C1 = ""
Range("G19").Select
ActiveCell.FormulaR1C1 = ""
Range("H19").Select
ActiveCell.FormulaR1C1 = ""
Range("F21").Select
ActiveCell.FormulaR1C1 = ""
Range("F23").Select
ActiveCell.FormulaR1C1 = ""
Range("H23:I23").Select
ActiveCell.FormulaR1C1 = ""
Range("F25").Select
ActiveCell.FormulaR1C1 = ""
Range("F27").Select
ActiveCell.FormulaR1C1 = ""
Range("F29").Select
ActiveCell.FormulaR1C1 = ""
Range("e31").Select
ActiveCell.Clear
Range("e32").Select
ActiveCell.Clear
Range("E34:F34").Select
ActiveCell.FormulaR1C1 = ""
Range("E36:F36").Select
ActiveCell.FormulaR1C1 = ""
Range("E38").Select
ActiveCell.Clear

ActiveWorkbook.save
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Workbook_BeforeClose(Cancel As Boolean)

see your problem now?
you must include "Cancel As Boolean" as an argument, but you don't have to do anything with it.
 
Upvote 0
I surfed around to find what I needed and ignored the boolean comment because I didn't know what it meant.

Figures it was too simple. Thanks!!
 
Upvote 0
Quick tip as well.

When you are in the worksheet or the workbook object you can access the events pretty easily (or userforms for that matter). There are two combo boxes at the top of the VBE when you are in these modules. The one on the left lets you select any object that is part of the object, the combobox on the right lets you choose an event. (this will help you to avoid missing out arguments in the future)

HTH.
 
Upvote 0

Forum statistics

Threads
1,213,549
Messages
6,114,261
Members
448,558
Latest member
aivin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top