Dim WithEvents xlApp As Excel.Applicaton Dim xlWb As Excel.WorkbookSet xlApp = New Excel.Application Set xlWb = xlApp.Workbooks.Open(sFileName).... Private Sub xlApp_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean) If Wb.Name = sTargetWorkbookName Then .... End If End Sub
Dim xlWb As Excel.WorkbookSet xlApp = New Excel.Application
Set xlWb = xlApp.Workbooks.Open(sFileName)....
Private Sub xlApp_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean)
If Wb.Name = sTargetWorkbookName Then
....
End If
End Sub