Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want help to remove custom created toolbar

Status
Not open for further replies.

Ken

IS-IT--Management
Jul 13, 2005
68
CA
All guru,

Below is the code I have written in VBA for creating a toolbar and using it whenever opening file a called MyWorkbook.xls file.

Problem is when I close myworkbook.xls file the custom toolbar is still available. I right clicked at the toolbar and can see the custom toolbar created by me.

How to delete custom toolbar when closing excel file.




Code in This Workbook

Private Sub Workbook_WindowActivate(ByVal Wn As _
Excel.Window)
If Application.CommandBars("Tool").Visible = True Then
Exit Sub
Else
Application.CommandBars("Tool").Visible = True
End If
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As _
Excel.Window)
If Application.CommandBars("Tool").Visible = True Then
Application.CommandBars("Tool").Visible = False

Exit Sub
Else
Exit Sub
End If
End Sub
 
TechIT05,

Code:
Application.CommandBars("Tool").Delete

Are you creating the CommandBar (Toolbar) with code? If so set the toolbar as Temporary.
Code:
Application.CommandBars.Add("Tool", , , [b]True[/b])

Otherwise you might use the [tt]Open()[/tt] and [tt]BeforeClose()[/tt] events of the workbook instead of Activate/Deactivate.

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Funny...

I've never used Workbook_WindowActivate or Workbook_WindowDeactivate. I've always used the plain Workbook_Activate and Workbook_Deactivate events for controlling if I want my menus rebuilt.

You may want to see if that makes any difference as well.

Ken Puls, CMA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top