Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Testing if Commandbar exists

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-


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Testing if Commandbar exists

On Sep 17, 6:18 pm, "Farrar Tweety"
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Testing if Commandbar exists

FarrarTweety,

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

"Farrar Tweety" wrote in message
...
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-



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Testing if Commandbar exists

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



"Farrar Tweety" 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-


--

Dave Peterson
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
Tag in CommandBar Desert Piranha[_99_] Excel Programming 4 August 10th 06 06:34 AM
cant dim as commandbar Seren Excel Programming 1 December 21st 05 09:18 PM
CommandBar swiederkehr Excel Programming 5 July 19th 05 04:58 PM
Testing to see if a Workbook menu item exists Todd Huttenstine[_3_] Excel Programming 2 December 31st 03 12:02 AM
Testing to see if a sheet name exists anita Excel Programming 1 September 4th 03 10:14 PM


All times are GMT +1. The time now is 09:00 PM.

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"