Excel Developer Tip


Return to The Spreadsheet Page

Excel page

Tip archives

Create a Toolbar on the Fly

You can create new CommandBars manually -- or you can do so with VBA. Creating a new toolbar on the fly is amazingly fast, and is really not very difficult to program.

This add-in creates a fairly complex toolbar that functions as a simple calculator. The add-in's VBA project is not protected, so you can view the code to see how it works.

The file demonstrates several useful VBA techniques, including:

  • Adding a menu item to the Tools menu
  • Creating a new CommandBar
  • Adding controls to the CommandBar
  • Adding a menu to a CommandBar (the Help menu, in the figure below)
  • Setting the CommandBar's properties so it can't be resize, customized, or docked.
  • Pasting data to a cell
  • Undoing the paste operation

To learn more about working with CommandBars using VBA, refer to Excel 2002 Power Programming With VBA.