O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The CommandBars Collection

The topmost object that relates to menus and toolbars is the CommandBars collection, which contains all of the application’s CommandBar objects. The CommandBars collection is accessible through the CommandBars property of the Application object; that is

	Application.CommandBars

(CommandBars is also a global property, so it can be used without the qualifying word “Application.”) The following code will print a list of all of the CommandBar objects to the Immediate window. I think you will be surprised at the large number of these objects, most of which are not currently visible:

	Dim sType as string, cbar as CommandBar
	For Each cbar In CommandBars
	  Select Case cbar.Type
	  Case msoBarTypeNormal
	     sType = "Normal"
	  Case msoBarTypeMenuBar
	     sType = "Menu bar"
	  Case msoBarTypePopup
	     sType = "Popup"
	  End Select
	  Debug.Print cbar.Name & "," & sType & "," & cbar.Visible
	Next

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required