Creating a menu

When you create a menu, you add a new word to a menu bar. The control that you add is of the Popup type because the menu always contains menu items.

The following procedure adds a new menu (Budgeting) between the Window menu and the Help menu on the Worksheet menu bar:

Sub

AddNewMenu()

Dim HelpIndex As Integer

Dim NewMenu As CommandBarPopup

Get Index of Help menu

HelpIndex = CommandBars(1).Controls("Help").Index

Create the control

Set NewMenu = CommandBars(l) _

.Controls.Add(Type:=msoControlPopup, _

Before:=HelpIndex, Temporary:=True)

Add a caption

NewMenu.Caption = "&Budgeting"

End

Sub

Notice that this procedure creates an essentially worthless menu — it has no menu items. See the next section, "Adding a menu item," for an example of adding a menu item to a menu. Figure 20-4 shows the Worksheet menu bar after executing this procedure.

This example is available on this book's Web site.

Adding the menu is a two-step process:

0 0

Post a comment