The workbook that is closing gets passed to that event:
sub moExcelApp_WorkbookBeforeClose(ByVal Wb As Excel.Workbook, _
Cancel As Boolean)
msgbox wb.fullname & " is closing now"
end sub
I'm not sure how you get the name of the worksheet when your routine opens up,
but if you can get the name of the worksheet, you can get the name of that
worksheet's parent (the workbook that contains that worksheet).
dim wks as worksheet
dim wksName as string
dim wkbkName as workbook
set wks = HowEverYouGetThatWorksheet
wksName = wks.name
wkbkname = wks.parent.fullname
The parent of the range is the the worksheet.
The parent of the worksheet is the workbook.
The parent of the workbook is the application (excel itself).
I think I start understanding that 'workbook' versus 'sheet' concept but
still have the same question.
How to check which workbook is being closed then?
At the start of my app I check for the open sheet (not workbook).
So I know the title of that sheet.
How can I compare title of that sheet with the workbook title being closed?
It looks like apples and oranges to me.
Other Excel events contain Sh as a parameter and that I understand.
But WorkbookBeforeClose() does NOT contain Sh but Wb.
What should I do?
Jack