30.04.2017 Views

4523756273

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 19: Accessing Your Macros through the User Interface<br />

Creating a Custom Toolbar<br />

If you check out all the CommandBars available, you may have noticed one<br />

called Built-in Menus. This CommandBar contains all the old Excel 2003 menu<br />

commands. Figure 19-9 shows part of this giant pop-up menu. All the old commands<br />

are there, but they aren’t arranged very well.<br />

329<br />

Figure 19-9:<br />

Displaying<br />

the Built-in<br />

Menus<br />

shortcut<br />

menu.<br />

In this example, I present a VBA procedure that (kind of) re-creates the old<br />

Excel 2003 menu bar. It creates a new CommandBar and then copies the controls<br />

from the Built-in Menus CommandBar.<br />

Sub MakeOldMenus()<br />

Dim cb As CommandBar<br />

Dim cbc As CommandBarControl<br />

Dim OldMenu As CommandBar<br />

‘ Delete it, if it exists<br />

On Error Resume Next<br />

Application.CommandBars(“Old Menus”).Delete<br />

On Error GoTo 0<br />

‘ Create an old-style toolbar<br />

‘ Set the last argument to False for a more compact menu<br />

Set OldMenu = Application.CommandBars.Add<br />

_(“Old Menus”, , True)<br />

‘ Copy the controls from Excel’s “Built-in Menus”<br />

shortcut menu<br />

With CommandBars(“Built-in Menus”)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!