Ensuring that an attached toolbar is displayed

As I explained earlier in this chapter, you can attach any number of toolbars to a workbook. But I also noted that the attached toolbar won't replace an existing toolbar that has the same name.

In some cases, the failure to display a toolbar can present a problem. For example, assume that you distribute a workbook to your coworkers, and this workbook has an attached toolbar that executes your macros. Later, you update the workbook and add some new controls to your attached toolbar. When you distribute this new workbook, the updated toolbar doesn't display because the old toolbar already exists!

One solution is to simply use a new toolbar name for the updated application. Perhaps a better solution is to write VBA code to delete the toolbar when the workbook closes. That way, the toolbar isn't stored on the user's system and you're assured that the latest copy of your toolbar is always displayed when the workbook opens.

The following procedure, which is stored in the code window for the ThisWorkbook object, displays the toolbar named Budget Tools when the workbook is opened. The Budget Tools toolbar is attached to the workbook.

0 0

Post a comment