first time class module
Thanks for your reply. I'm trying to get the custom toolbars called
when each sheet in the workbook is selected, to hide when the workbook
is closed, so I guess it's a document level macro.
Peter T wrote:
Private Sub appevents_beforeclose()
This event traps workbook level events
Public WithEvents AppEvents As Workbook
I changed "Private Sub appevents_beforeclose()" to "Public WithEvents
AppEvents As Workbook" in the class module "HideToolbar".
and in the normal module change
Set AppObject.AppEvents = Application
to
Set AppObject.AppEvents = workbooks("myBook.xls")
or = some ref to the particular workbook.
I changed "Set AppObject.AppEvents = Application" to "Set
AppObject.AppEvents = workbooks("PIP DD Template.xls")" in the regular
module.
But it still doesn't work. Any other ideas?
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.
I'm not following you here. Do you mean left and right dropdowns? The
left one is toward the middle of the VBE, is that what you mean by "top
middle"?
Can you elaborate on this? I'm not sure what you mean by "select
withevents var' name".
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.
|