T
triaz
Hi,
I have a custom menu that is re-created each time the excel app is
opened. This custom menu is part of an addin.
Since I need my menu to enable and disable menu items depending on
whether a workbook is open, or on other conditions such as the sheet
name, I thought by having a procedure which is triggered by the
NewMenu' onAction event, which would then check against these
conditions before the menu displays, would be perfect.
I tested the procedure before adding to the onAction event and it
worked fine, but when I placed this procedure on the NewMenu' onAction
event nothing worked.
I did have an Application level event which did this but it was erratic
ie did not work when there were no workbooks open.
Here's the code I have:
Sub CreateMenu()
'some code here
With NewMenu
.Caption = "Storyboard"
.onAction = "checkMyStatus"
End With
'menuitems added here ...
End Sub
Sub checkMyStatus()
Call checkWorkbook
Call checkWorksheet
End Sub
Sub checkWorkbook()
On Error Resume Next
If Workbooks.Count < 2 Then
CommandBars(1).Controls("Storyboard").Controls("&Add
Topic").Enabled = False
CommandBars(1).Controls("Storyboard").Controls("&Edit Course
Info").Enabled = False
CommandBars(1).Controls("Storyboard").Controls("&Tools").Enabled =
False
CommandBars(1).Controls("Storyboard").Controls("&Insert").Enabled =
False
CommandBars(1).Controls("Storyboard").Controls("&Word
Count").Enabled = False
CommandBars(1).Controls("Storyboard").Controls("&Print
Storyboard").Enabled = False
Else: Call EnableMenuItems
End If
End Sub
Sub checkWorksheet()
similar to checkWorkbook
End Sub
Sub EnableMenuItems()
On Error Resume Next
CommandBars(1).Controls("Storyboard").Controls("&Add
Topic").Enabled = True
CommandBars(1).Controls("Storyboard").Controls("&Edit Course
Info").Enabled = True
CommandBars(1).Controls("Storyboard").Controls("&Tools").Enabled =
True
CommandBars(1).Controls("Storyboard").Controls("&Insert").Enabled =
True
CommandBars(1).Controls("Storyboard").Controls("&Word
Count").Enabled = True
CommandBars(1).Controls("Storyboard").Controls("&Print
Storyboard").Enabled = True
End Sub
What am I doing wrong?
Thanks in advance.
Regards
T.
I have a custom menu that is re-created each time the excel app is
opened. This custom menu is part of an addin.
Since I need my menu to enable and disable menu items depending on
whether a workbook is open, or on other conditions such as the sheet
name, I thought by having a procedure which is triggered by the
NewMenu' onAction event, which would then check against these
conditions before the menu displays, would be perfect.
I tested the procedure before adding to the onAction event and it
worked fine, but when I placed this procedure on the NewMenu' onAction
event nothing worked.
I did have an Application level event which did this but it was erratic
ie did not work when there were no workbooks open.
Here's the code I have:
Sub CreateMenu()
'some code here
With NewMenu
.Caption = "Storyboard"
.onAction = "checkMyStatus"
End With
'menuitems added here ...
End Sub
Sub checkMyStatus()
Call checkWorkbook
Call checkWorksheet
End Sub
Sub checkWorkbook()
On Error Resume Next
If Workbooks.Count < 2 Then
CommandBars(1).Controls("Storyboard").Controls("&Add
Topic").Enabled = False
CommandBars(1).Controls("Storyboard").Controls("&Edit Course
Info").Enabled = False
CommandBars(1).Controls("Storyboard").Controls("&Tools").Enabled =
False
CommandBars(1).Controls("Storyboard").Controls("&Insert").Enabled =
False
CommandBars(1).Controls("Storyboard").Controls("&Word
Count").Enabled = False
CommandBars(1).Controls("Storyboard").Controls("&Print
Storyboard").Enabled = False
Else: Call EnableMenuItems
End If
End Sub
Sub checkWorksheet()
similar to checkWorkbook
End Sub
Sub EnableMenuItems()
On Error Resume Next
CommandBars(1).Controls("Storyboard").Controls("&Add
Topic").Enabled = True
CommandBars(1).Controls("Storyboard").Controls("&Edit Course
Info").Enabled = True
CommandBars(1).Controls("Storyboard").Controls("&Tools").Enabled =
True
CommandBars(1).Controls("Storyboard").Controls("&Insert").Enabled =
True
CommandBars(1).Controls("Storyboard").Controls("&Word
Count").Enabled = True
CommandBars(1).Controls("Storyboard").Controls("&Print
Storyboard").Enabled = True
End Sub
What am I doing wrong?
Thanks in advance.
Regards
T.