Menu help

StevenD

Active Member
Joined
Nov 17, 2004
Messages
262
Hi,
I'm using the following code to create a menu.
Code:
Sub Add_Workbook_Menu_And_Items() 
Dim newMenu, newMenuItem 
On Error GoTo oops 
'delete the menu if it exists by calling this subroutine 
Remove_Workbook_Menu 
With CommandBars("Worksheet Menu Bar") 
Set newMenu = .Controls.Add(Type:=msoControlPopup, before:=.Controls("Window").Index, temporary:=True) 
End With 
'give the new menu a name 
newMenu.Caption = "&Controls" 
'add a menu item to the new menu 
Set newMenuItem = newMenu.Controls.Add(Type:=msoControlButton) 
'give the new menu a name and assign a macro to it 
newMenuItem.Caption = "&Start Comms" 
newMenuItem.OnAction = "comstart" 
Set newMenuItem = newMenu.Controls.Add(Type:=msoControlButton) 
'give the new menu a name and assign a macro to it 
newMenuItem.Caption = "&Stop Comms" 
newMenuItem.OnAction = "comstop" 
Set newMenuItem = newMenu.Controls.Add(Type:=msoControlButton) 
'give the new menu a name and assign a macro to it 
newMenuItem.Caption = "&Get Settings" 
newMenuItem.OnAction = "settings" 
Exit Sub 
oops: 
MsgBox "An error has occured, cannot create the menu items. " & Chr(13) & Chr(13) & _ 
"Error number: " & Err.Number & Chr(13) & "Error Description: " & Err.Description, vbCritical + vbOKOnly, "Ooops..." 
Application.ScreenUpdating = True 
End Sub

What I would like is for the Get Settings item only to be active when comms has been started and greyed out the rest of the time.

Similarly when comms has been started I want it to be greyed out and when stopped for stop comms to be greyed out.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
How do you know when comstart or comstop has been run? What way do you have to check that? If you return it to a Boolean (True/False) then you can add a line ...


Code:
newMenuItem.Caption = "&Get Settings" 
newMenuItem.OnAction = "settings"
'... \/ ADD LINE HERE \/ ...
If blnCheck = True then newMenuItem.Enabled = False
'... REST OF CODE ...

Now what you use as blnCheck is up to you. If you would expand on it, we could provide some help there - if you need it.

HTH
 
Upvote 0

Forum statistics

Threads
1,216,130
Messages
6,129,062
Members
449,484
Latest member
khairianr

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
Back
Top