Iron Man
Iron Man

Reputation: 849

Compile Error Opening Workbook in Excel 2007

I have a code that I am running that is stored in ThisWorkbook. It was originally Private Sub Workbook_Activate and Private Sub Workbook_Deactivate. This was causing some unexpected results when switching between open workbooks. So I have changed the code to what is below. Only now, I get a compile error message (the Private Sub Workbook_BeforeClose is highlighted when I get this error message) that says:

Compile error:

Procedure declaration does not match description of event or procedure having the same name.

I am not savvy enough in VBA to understand this error message or a good fix for it. All help and suggestions are welcome.

Private Sub Workbook_Open()
    Call AddToCellMenu
End Sub

Private Sub Workbook_BeforeClose()
    Call DeleteFromCellMenu
    Call DeletePopUpMenu
End Sub

Upvotes: 0

Views: 310

Answers (1)

barrowc
barrowc

Reputation: 10679

It should be:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

The Cancel parameter is there to let you prevent the workbook from closing - e.g. if certain conditions haven't been met. Setting Cancel to True stops the workbook from closing - see the Workbook.BeforeClose documentation

Upvotes: 1

Related Questions