Testing if Commandbar exists

  • Thread starter Thread starter Farrar > Tweety
  • Start date Start date
F

Farrar > Tweety

Can't seem to get a handle on this. How would I test, in VBA, if the
toolbar "My Tools" exists? Any help appreciated, in the meantime I'm going
to keep hammering away.

-gk-
 
Can't seem to get a handle on this. How would I test, in VBA, if the
toolbar "My Tools" exists? Any help appreciated, in the meantime I'm going
to keep hammering away.

-gk-

Hello,

Here is a code example...

Dim CmdBar As CommandBar
Dim Exists As Boolean

For Each CmdBar In Application.CommandBars
If CmdBar.Name = "My Tools" Then
Exists = True
Exit Loop
End If
Next CmdBar

Sincerely,
Leith Ross
 
Farrar>Tweety,

Here's a function to test it:

Function CommandbarExists(CommandBarName) As Boolean
Dim cbar As CommandBar
On Error Resume Next
Set cbar = Application.CommandBars(CommandBarName)
If Err.Description = "" Then
CommandbarExists = True
End If
End Function

Run the test sub below and you should get "True" and then "False" in the
immediate window, unless you have a commandbar called "Foo":

Sub test()
Debug.Print CommandbarExists("Standard")
Debug.Print CommandbarExists("Foo")
End Sub

hth,

Doug
 
dim myCmdBar as CommandBar

set mycmdbar = nothing
on error resume next
set mycmdbar = application.commandbars("my tools")
on error goto 0

if mycmdbar is nothing then
'doesn't exist
else
'yep, it exists
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top