Checking for a Menu Control

viper

Active Member
Joined
Feb 15, 2002
Messages
382
I have a spreadsheet that adds a new control called Figures upon opening and then it deletes it upon closing.

What I'm wanting to do is be able to check for that control in the workbook_activate event, if it's there then do nothing, if not then add it.

The reason being, I have 9 of these workbooks that get sent out, when I receive all 9 back and open two or more at the same time, I don't want the control to be deleted when I close one of the workbooks.

So I figure if I can check it in the activate_event, when I close one workbook and it deletes it, when the next one is activated it will add it back.

Is there a way to check to for menu controls?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

ACommandLineKindaGuy

Active Member
Joined
May 11, 2002
Messages
324
Office Version
  1. 365
Platform
  1. Windows
You didn't specify where the control is, so use the following as an example:

Code:
Private Sub Workbook_Activate()       'Executed after 'Workbook_Open'

'Test if another workbook that uses the control is open by making the
'control visible.  If an Err.Number is generated, no other workbook
'using the control is open so it must be created, otherwise it's made visible
On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("MyControl").Visible = True
If Err.Number <> 0 Then
'...'MyControl' menu does not exist, so create it
    'code to create here
End If
'continue doing whatever here

Of course, now you'll need to make the control hidden when you deactivate the workbook...

Regards, John
 

Forum statistics

Threads
1,147,845
Messages
5,743,513
Members
423,801
Latest member
paulj4177

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top