Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default toolbar won't go away

I'm trying to add/remove command bar in code. It is created fine, but
persists after workbook is closed.

In ThisWorkbook code I have:

Sub Workbook_Open()
Call BuildToolBar
End Sub
Sub Workbook_Close()
Call RemoveToolBar
End Sub

In code module, I have:

Sub BuildToolBar()
Dim cb As CommandBar
Dim cbcCommandBarButton1 As CommandBarButton
Dim cbcCommandBarButton2 As CommandBarButton

'delete commandbar if it exists
On Error Resume Next
Application.CommandBars.Item("Prep Actual Costs").Delete
On Error GoTo 0

'create new commandbar
Set cb = Application.CommandBars.Add(Name:="Prep Actual Costs",
Position:=msoBarTop)
Set cbcCommandBarButton1 = cb.Controls.Add(Type:=msoControlButton)
With cbcCommandBarButton1
.Caption = "&Prep Actuals"
.OnAction = "'" & ThisWorkbook.Name & "'!PrepActuals"
.FaceId = 2950
.Style = msoButtonIconAndCaption
End With

Set cbcCommandBarButton2 = cb.Controls.Add(Type:=msoControlButton)
With cbcCommandBarButton2
.Caption = "&Show Labor Lookup"
.OnAction = "'" & ThisWorkbook.Name & "'!ShowLaborLookup"
.FaceId = 19
.Style = msoButtonIconAndCaption
End With

cb.Visible = True
End Sub
Sub RemoveToolBar()
On Error Resume Next
Application.CommandBars("Prep Actual Costs").Delete
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default toolbar won't go away

Just try putting the code in the Auto_Close Event

Sub Auto_Close()
On Error Resume Next
CommandBars("Prep Actual Costs").Delete
End sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default toolbar won't go away

I'd already put it in Workbook_BeforeClose, and that fixed the problem.
Is Auto_Close more appropriate?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default toolbar won't go away

Sorry can't help you there about appropriate or best

As I only have the basics, it's just how I do it and it works so I keep
doing it

"sugargenius" wrote in message
ups.com...
I'd already put it in Workbook_BeforeClose, and that fixed the problem.
Is Auto_Close more appropriate?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default toolbar won't go away

I don't have to worry about the distinction. Auto_Close didn't work.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default toolbar won't go away

In the ThisWorkbook, Userform and Sheet modules, you would be advised to
select your event procedures from the dropdowns at the top of the module.
This will eliminate misnaming your procedures as you show you have done.

The Auto_Close macro, in a general module was used to perform this function
in xl95 and xl5. The newer generation of events was added in xl97.

Probably better to use the BeforeClose Event.

http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy


"sugargenius" wrote in message
ups.com...
I'd already put it in Workbook_BeforeClose, and that fixed the problem.
Is Auto_Close more appropriate?



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default toolbar won't go away

Auto_close has to be in a general module, not the ThisWorkbook module.

--
Regards,
Tom Ogilvy

"sugargenius" wrote in message
oups.com...
I don't have to worry about the distinction. Auto_Close didn't work.



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default toolbar won't go away

Thanks for the clariffication


"Tom Ogilvy" wrote in message
...
In the ThisWorkbook, Userform and Sheet modules, you would be advised to
select your event procedures from the dropdowns at the top of the module.
This will eliminate misnaming your procedures as you show you have done.

The Auto_Close macro, in a general module was used to perform this
function
in xl95 and xl5. The newer generation of events was added in xl97.

Probably better to use the BeforeClose Event.

http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default toolbar won't go away

I'd never noticed that. Thanks

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default toolbar won't go away

When you add the commandbar, specify the "Temporary" option to "True", then
it will be deleted automatically when Excel was closed.

Application.CommandBars.Add(Temporary:=True)

Hope this helps.

"sugargenius" wrote:

I'm trying to add/remove command bar in code. It is created fine, but
persists after workbook is closed.

In ThisWorkbook code I have:

Sub Workbook_Open()
Call BuildToolBar
End Sub
Sub Workbook_Close()
Call RemoveToolBar
End Sub

In code module, I have:

Sub BuildToolBar()
Dim cb As CommandBar
Dim cbcCommandBarButton1 As CommandBarButton
Dim cbcCommandBarButton2 As CommandBarButton

'delete commandbar if it exists
On Error Resume Next
Application.CommandBars.Item("Prep Actual Costs").Delete
On Error GoTo 0

'create new commandbar
Set cb = Application.CommandBars.Add(Name:="Prep Actual Costs",
Position:=msoBarTop)
Set cbcCommandBarButton1 = cb.Controls.Add(Type:=msoControlButton)
With cbcCommandBarButton1
.Caption = "&Prep Actuals"
.OnAction = "'" & ThisWorkbook.Name & "'!PrepActuals"
.FaceId = 2950
.Style = msoButtonIconAndCaption
End With

Set cbcCommandBarButton2 = cb.Controls.Add(Type:=msoControlButton)
With cbcCommandBarButton2
.Caption = "&Show Labor Lookup"
.OnAction = "'" & ThisWorkbook.Name & "'!ShowLaborLookup"
.FaceId = 19
.Style = msoButtonIconAndCaption
End With

cb.Visible = True
End Sub
Sub RemoveToolBar()
On Error Resume Next
Application.CommandBars("Prep Actual Costs").Delete
End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel toolbar like word toolbar, please Meng[_2_] Excel Discussion (Misc queries) 1 May 23rd 09 04:28 PM
Form Toolbar verses Control Toolbar ub Excel Discussion (Misc queries) 3 July 11th 08 10:57 PM
Save Toolbar into new toolbar [email protected] Excel Discussion (Misc queries) 2 March 4th 08 11:16 AM
Adjusting toolbar size, restore toolbar Josh M Excel Discussion (Misc queries) 1 January 18th 06 06:17 PM
saving toolbar buttons on custom toolbar Paul James Excel Programming 12 August 6th 03 08:28 AM


All times are GMT +1. The time now is 07:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"