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- |
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 |
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- |
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 |
All times are GMT +1. The time now is 08:23 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com