The answer to your problem is to associate the code with the SheetActivate / SheetDeactivate events.
Go to the codepage associated with ThisWorkbook for whichever project you are working in.
At the top left of the actual CodePage, there is a dropdown that probably says '(General)'. Click this and select 'Workbook'. You will now see that top right dropdown's contents have changed (and Excel has probably created a 'Workbook_Open' event stub for you).
Click on the dropdown and select 'SheetActivate', you will see Excel place an Event stub on the CodePage for you. All you need to do now is place the code to enable your CommandBar here.
If you only want the command bar to appear for certain sheets, you can use the Default parameter 'sh' to determine the name of the activated worksheet (i.e. sh.Name) and write conditional logic for your particular scenario.
Don't forget to do the same thing for the 'SheetDeactivate' event, too.
Chris
There are two secrets to success in this world:
1. Never tell everything you know
|