ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to limit custom toolbar's display (https://www.excelbanter.com/excel-programming/401358-how-limit-custom-toolbars-display.html)

Dingding

how to limit custom toolbar's display
 
Hi, all

I am working on an application in Excel and I add a new toolbar to
excel by coding VBA. Here's the way that I wrote like:

Application.CommandBars.Add Name:= "My Toolbar", Temporary:=True

But if I open other excel workbooks at the same time, the toolbar also
appears in the window of those workbooks. It's really annoying and
leads to mistakes. Is there any way to prevent the toolbar displaying
in unrelated workbooks?

Thanks for any suggestions.

Dingding

[email protected]

how to limit custom toolbar's display
 
On Nov 19, 3:13 pm, Dingding wrote:
Hi, all

I am working on an application in Excel and I add a new toolbar to
excel by coding VBA. Here's the way that I wrote like:

Application.CommandBars.Add Name:= "My Toolbar", Temporary:=True

But if I open other excel workbooks at the same time, the toolbar also
appears in the window of those workbooks. It's really annoying and
leads to mistakes. Is there any way to prevent the toolbar displaying
in unrelated workbooks?

Thanks for any suggestions.

Dingding


Hi
If your code that inserts the menu is called CreateMenu() and your
code that removes the menu is called DestroyMenu() then create these
two subs in the ThisWorkBook code module;

Private Sub Workbook_Activate()
Call CreateMenu
End Sub
Private Sub Workbook_Deactivate()
Call DestroyMenu
End Sub

The Create and Destroy subs would be what you would have in your Open
and BeforeClose macros to add and remove the menu when you open/close
Excel.

regards
Paul

Dingding

how to limit custom toolbar's display
 
On 11月19日, 下午11时22分, wrote:
On Nov 19, 3:13 pm, Dingding wrote:

Hi, all


I am working on an application in Excel and I add a new toolbar to
excel by coding VBA. Here's the way that I wrote like:


Application.CommandBars.Add Name:= "My Toolbar", Temporary:=True


But if I open other excel workbooks at the same time, the toolbar also
appears in the window of those workbooks. It's really annoying and
leads to mistakes. Is there any way to prevent the toolbar displaying
in unrelated workbooks?


Thanks for any suggestions.


Dingding


Hi
If your code that inserts the menu is called CreateMenu() and your
code that removes the menu is called DestroyMenu() then create these
two subs in the ThisWorkBook code module;

Private Sub Workbook_Activate()
Call CreateMenu
End Sub
Private Sub Workbook_Deactivate()
Call DestroyMenu
End Sub

The Create and Destroy subs would be what you would have in your Open
and BeforeClose macros to add and remove the menu when you open/close
Excel.

regards
Paul


Hi,

Your suggestion works! Thanks a lot. :-)

Dingding


All times are GMT +1. The time now is 02:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com