ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding and Removing Custom Menu Items for one file... (https://www.excelbanter.com/excel-programming/277328-adding-removing-custom-menu-items-one-file.html)

Jon Kane

Adding and Removing Custom Menu Items for one file...
 
I created a vba program in excel that creates a menu item on the main menu
bar when the file is opened and remove it when the file is closed. I use
the Workbook_Open and Workbook_BeforeClose functions. However, if I open
the file twice it gives me 2 of the menu items, and when I exit only the
file and not the application, the menu items remain. Is there a way to get
it to only add them menu item when the file is opened and then remove it
when that file is closed???? Thanks for the help.

--Jon



steve

Adding and Removing Custom Menu Items for one file...
 
Jon,

In your Workbook_Open macro first delete than build...

On Error Resume Next
Application.CommandBars("mybar").Delete
On Error GoTo 0

--
sb
"Jon Kane" wrote in message
...
I created a vba program in excel that creates a menu item on the main menu
bar when the file is opened and remove it when the file is closed. I use
the Workbook_Open and Workbook_BeforeClose functions. However, if I open
the file twice it gives me 2 of the menu items, and when I exit only the
file and not the application, the menu items remain. Is there a way to

get
it to only add them menu item when the file is opened and then remove it
when that file is closed???? Thanks for the help.

--Jon





Jean-Paul Viel

Adding and Removing Custom Menu Items for one file...
 
Hi,



If MyMenu.Visible=True then exit sub



Your menu won't be added twice.




--
JP

http://www.solutionsvba.com


"Jon Kane" wrote in message
...
I created a vba program in excel that creates a menu item on the main menu
bar when the file is opened and remove it when the file is closed. I use
the Workbook_Open and Workbook_BeforeClose functions. However, if I open
the file twice it gives me 2 of the menu items, and when I exit only the
file and not the application, the menu items remain. Is there a way to

get
it to only add them menu item when the file is opened and then remove it
when that file is closed???? Thanks for the help.

--Jon






All times are GMT +1. The time now is 12:35 PM.

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