سؤال

In my ongoing battle to create this simple add-in for work.

I've now decided to toggle the reminder on and off using a command button inside a command bar, this is the code I have below.

Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
Dim cmbBar As CommandBar
Dim cmbControl As CommandBarControl

Set cmbBar = Application.CommandBars("Worksheet Menu Bar")
Set cmbControl = cmbBar.Controls.Add(Type:=msoControlPopup, temporary:=True) 'adds a menu item to the Menu Bar
With cmbControl
    .Caption = "LLE Encryption Reminder" 'names the menu item
With .Controls.Add(Type:=msoControlButton) 'adds a dropdown button to the menu item
    .Caption = "Enable Reminder" 'adds a description to the menu item
    .OnAction = "'Enable'"
    .FaceId = 343 'assigns an icon to the dropdown
    End With
With .Controls.Add(Type:=msoControlButton) 'adds a dropdown button to the menu item
    .Caption = "Disable Reminder" 'adds a description to the menu item
    .OnAction = "'Disable'"
    .FaceId = 342 'assigns an icon to the dropdown
    End With
End With
End Sub

Private Sub Enable()
Response = True
End Sub

Private Sub Disable()
Response = False
End Sub

Response is a boolean, I've tried all sorts to get this to work and it returns the same error each and every time "Cannot run the macro "pathname". The macro may not be available in this workbook or all macros may be disabled.

How do you overcome this problem?

Also whilst on the same topic, Is there anyway for me to show some sort of label showing the status of response?

This code is in a class module called CExcelEvents after reading Application Events In A New Class Module from this website http://www.cpearson.com/Excel/AppEvent.aspx I came under the impression my code for my addin needs to go in the same class module, am I wrong to assume this? In ThisWorkbook I have the following code which is used to make my class module work.

Private XLApp As CExcelEvents

Private Sub Workbook_Open()
Set XLApp = New CExcelEvents
End Sub
هل كانت مفيدة؟

المحلول

I fixed this problem by moving the subs and public variables into a separate module instead of a class module, this then sorted the problem I had.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top