Workbook Switching Strategy
Nigel,
This code, adapted from a previous post, seems to work fine for me
Private VisibleState()
Private Sub Workbook_Activate()
Dim a As Long
Dim cCBs As Long
Application.CommandBars("Worksheet Menu Bar").Enabled = False
ReDim VisibleState(1)
cCBs = 1
For a = 2 To Application.CommandBars.Count
If Application.CommandBars(a).Visible = True Then
ReDim Preserve VisibleState(cCBs)
VisibleState(cCBs) = Application.CommandBars(a).Name
Application.CommandBars(a).Visible = False
cCBs = cCBs + 1
End If
Next a
End Sub
Sub Workbook_Deactivate()
Dim a As Long
Application.CommandBars("Worksheet Menu Bar").Enabled = True
For a = LBound(VisibleState) To UBound(VisibleState)
Application.CommandBars(VisibleState(a)).Visible = True
Next a
End Sub
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Nigel" wrote in message
...
Hi All
I have an application (my-application) that replaces Excel standard
toolbars
with a custom toolbar, the toolbars are restored if the user closes the
my-application.
If however my-application is running and the user chooses to create or
open
another workbook, I need to ensure that the custom toolbar is removed and
the standard toolbars restored, if they switch back to the my-application
then the reverse action is required, the procedure that turns of the
standard tool bars and creates the customer toolbar runs again.
I have been trying to use windows and workbook activate and workbook
deactivate events without much success, it appears the focus on
my-application is lost immediately these events are triggered - what is
the
optimum strategy to achieve this switching?
TIA
--
Cheers
Nigel
|