Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Danielle Daniels   on Jan 28 In MS Office Category.

  
Question Answered By: Clayton Richardson   on Jan 28

Never tried, but it'll be similar to other collections presumably. E.g.

> Application.CommandBars("Freddie").Controls.Add

tells me that there is a CommandBars collection. A couple of ways to go
about these things ...

- you can scan the collection and look at the names to see if you find the
one you want

- you can put "on error resume next" / "on error goto 0" statements around a
statement that Sets a variable equal to the particular command bar. If the
variable ends up with nothing in it, then it doesn't exist. E.g. (just had
a play):

Option Explicit

Private Sub CommandButton1_Click()
Dim FreddieBar As CommandBar: Set FreddieBar = Nothing
On Error Resume Next
Set FreddieBar = Application.CommandBars("Freddie")
On Error GoTo 0
If FreddieBar Is Nothing Then
Call MsgBox("doesn't exist")
Else
Call MsgBox("does exist")
Application.CommandBars("Freddie").Delete
End If

Application.CommandBars.Add(Name:="Freddie").Visible = True

Set FreddieBar = Nothing
On Error Resume Next
Set FreddieBar = Application.CommandBars("Freddie")
On Error GoTo 0
If FreddieBar Is Nothing Then
Call MsgBox("doesn't exist")
Else
Call MsgBox("does exist")
Application.CommandBars("Freddie").Delete
End If
End Sub

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Custom Toolbars Usable by any User Or get search suggestion and latest updates.


Tagged: