first time class module
Private Sub appevents_beforeclose()
This event traps workbook level events
Public WithEvents AppEvents As Workbook
and in the normal module change
Set AppObject.AppEvents = Application
to
Set AppObject.AppEvents = workbooks("myBook.xls")
or = some ref to the particular workbook.
But if you want to trap events at application level
Private Sub AppEvents_WorkbookBeforeClose(ByVal Wb As Workbook, _
Cancel As Boolean)
If Wb.Name = "MyBook.xls" Then
Application.CommandBars("Abuse").Visible = False
End If
End Sub
Tip - instead of writing or pasting first & last event lines, select your
withevents var' name in the top middle dropdown, then find your event in the
top right dropdown.
Regards,
Peter T
"davegb" wrote in message
oups.com...
I want to hide a toolbar called "Abuse" when the workbook closes. I
looked it up in Walkenbach and tried to modify the code I found there
for my purpose. It doesn't work, but it doesn't hang either. Surprising
that it doesn't hang up.
Here is the code from the Class Module "HideToolbar"
Public WithEvents AppEvents As Application
Private Sub appevents_beforeclose()
Application.CommandBars("Abuse").Visible = False
End Sub
Here is the code from "ThisWorkbook":
Private Sub BeforeClose()
Call Init
End Sub
Here's the code from the regular module:
Dim AppObject As New HideToolbar
Sub Init()
Set AppObject.AppEvents = Application
End Sub
Any ideas on why it doesn't hide the toolbar?
Thanks in advance.
|