![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Location: Melbourne, Australia
Posts: 37
|
I am running a macro which creates a new sheet, creates a new toolbar and makes it visible on the worksheet. The problem is, if you run the macro again in the same Excel session, the toolbar is already there but the macro tries to create it again which causes an error. Is there any way to say, "Look for this toolbar; if it exists show it, if it doesn't exist, create it?"
My code is Application.CommandBars.Add(Name:="Custom Views").Visible = True |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
there is another way using the command bar feature
but if you put this code right before the toolbar code on error resume next it will bypass the error for you. |
|
|
|
|
|
#3 |
|
New Member
Join Date: May 2002
Location: Melbourne, Australia
Posts: 37
|
This works great! (by the way I went to university in Chch...) however my code goes:
Application.CommandBars.Add(Name:="Custom Views").Visible = True Application.CommandBars("Custom Views").Controls.Add Type:=msoControlComboBox _ , ID:=950, Before:=1 So if I use your code, it bypasses the "Create" but then goes to the "Add Control". So when I run the macro again, it keeps adding this control again to my toolbar, so I have two "custom view" windows showing on the toolbar. Any ideas? |
|
|
|
|
|
#4 |
|
New Member
Join Date: May 2002
Location: Melbourne, Australia
Posts: 37
|
Never mind - solved it myself using
On Error GoTo J (create toolbar) (add control to toolbar) J: (show toolbar) Thanks! |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|