Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Testing if Commandbar exists

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Farrar > Tweety - 18 Sep 2007 02:18 GMT
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-
Leith Ross - 18 Sep 2007 03:39 GMT
On Sep 17, 6:18 pm, "Farrar > Tweety" <toxicdistort...@hotmail.com>
wrote:
> 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
Doug Glancy - 18 Sep 2007 04:09 GMT
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

> 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-
Dave Peterson - 18 Sep 2007 04:14 GMT
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

> 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-

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.