Custom right click menu Excel Add-in not loading











up vote
0
down vote

favorite












I've used the Ron de Bruin tutorial to create a custom right click menu.
This works no problem when using it in an XLSM file type, but when I try to turn this into an Excel Add-in, the right click menu doesn't appear. Is there something specific I need to add in to the code to enable it?



The code I used in 'ThisWorkbook' is:



Private Sub Workbook_Activate()
Call AddToCellMenu
End Sub

Private Sub Workbook_Deactivate()
Call DeleteFromCellMenu
End Sub


The code I used in a separate module is:



Sub AddToCellMenu()
Dim ContextMenu As CommandBar
Dim MySubMenu As CommandBarControl

Call DeleteFromCellMenu

Set ContextMenu = Application.CommandBars("Cell")

Set MySubMenu = ContextMenu.Controls.Add(Type:=msoControlPopup, before:=3)

With MySubMenu
.Caption = "Recruitment"
.Tag = "My_Cell_Control_Tag"

With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & "Rejections"
.FaceId = 97
.Caption = "Format Rejections"
End With
With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & "Hires"
.FaceId = 87
.Caption = "Format Hires"
End With

End With

ContextMenu.Controls(4).BeginGroup = True
End Sub



Sub DeleteFromCellMenu()
Dim ContextMenu As CommandBar
Dim ctrl As CommandBarControl

Set ContextMenu = Application.CommandBars("Cell")

For Each ctrl In ContextMenu.Controls
If ctrl.Tag = "My_Cell_Control_Tag" Then
ctrl.Delete
End If
Next ctrl

On Error Resume Next
ContextMenu.FindControl(ID:=3).Delete
On Error GoTo 0
End Sub


Rejections and Hires are the two macros I'm asking for it to call. These are simple macros that I know work ok so didn't bother adding the code for those.










share|improve this question
























  • Please edit your question and show exactly the code you use in your project (alternatively add a Minimal, Complete, and Verifiable example). Links to similar code are not sufficient we need to see your code (links might break in future and the question becomes useless to other readers). Also note that "it won't work" is no useful error description. Tell us which error you get and in which line or what your code actually does vs. what you expect it to do.
    – Pᴇʜ
    Nov 19 at 10:42








  • 2




    If you're using an add-in, you probably want the Workbook_Open and Workbook_BeforeClose events rather than the Activate/Deactivate ones.
    – Rory
    Nov 19 at 10:51










  • @Rory that seems to have done the trick. The Workbook_BeforeClose command didn't work so I reverted to using deactivate. Thank you.
    – S. Laycock
    Nov 19 at 11:35

















up vote
0
down vote

favorite












I've used the Ron de Bruin tutorial to create a custom right click menu.
This works no problem when using it in an XLSM file type, but when I try to turn this into an Excel Add-in, the right click menu doesn't appear. Is there something specific I need to add in to the code to enable it?



The code I used in 'ThisWorkbook' is:



Private Sub Workbook_Activate()
Call AddToCellMenu
End Sub

Private Sub Workbook_Deactivate()
Call DeleteFromCellMenu
End Sub


The code I used in a separate module is:



Sub AddToCellMenu()
Dim ContextMenu As CommandBar
Dim MySubMenu As CommandBarControl

Call DeleteFromCellMenu

Set ContextMenu = Application.CommandBars("Cell")

Set MySubMenu = ContextMenu.Controls.Add(Type:=msoControlPopup, before:=3)

With MySubMenu
.Caption = "Recruitment"
.Tag = "My_Cell_Control_Tag"

With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & "Rejections"
.FaceId = 97
.Caption = "Format Rejections"
End With
With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & "Hires"
.FaceId = 87
.Caption = "Format Hires"
End With

End With

ContextMenu.Controls(4).BeginGroup = True
End Sub



Sub DeleteFromCellMenu()
Dim ContextMenu As CommandBar
Dim ctrl As CommandBarControl

Set ContextMenu = Application.CommandBars("Cell")

For Each ctrl In ContextMenu.Controls
If ctrl.Tag = "My_Cell_Control_Tag" Then
ctrl.Delete
End If
Next ctrl

On Error Resume Next
ContextMenu.FindControl(ID:=3).Delete
On Error GoTo 0
End Sub


Rejections and Hires are the two macros I'm asking for it to call. These are simple macros that I know work ok so didn't bother adding the code for those.










share|improve this question
























  • Please edit your question and show exactly the code you use in your project (alternatively add a Minimal, Complete, and Verifiable example). Links to similar code are not sufficient we need to see your code (links might break in future and the question becomes useless to other readers). Also note that "it won't work" is no useful error description. Tell us which error you get and in which line or what your code actually does vs. what you expect it to do.
    – Pᴇʜ
    Nov 19 at 10:42








  • 2




    If you're using an add-in, you probably want the Workbook_Open and Workbook_BeforeClose events rather than the Activate/Deactivate ones.
    – Rory
    Nov 19 at 10:51










  • @Rory that seems to have done the trick. The Workbook_BeforeClose command didn't work so I reverted to using deactivate. Thank you.
    – S. Laycock
    Nov 19 at 11:35















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I've used the Ron de Bruin tutorial to create a custom right click menu.
This works no problem when using it in an XLSM file type, but when I try to turn this into an Excel Add-in, the right click menu doesn't appear. Is there something specific I need to add in to the code to enable it?



The code I used in 'ThisWorkbook' is:



Private Sub Workbook_Activate()
Call AddToCellMenu
End Sub

Private Sub Workbook_Deactivate()
Call DeleteFromCellMenu
End Sub


The code I used in a separate module is:



Sub AddToCellMenu()
Dim ContextMenu As CommandBar
Dim MySubMenu As CommandBarControl

Call DeleteFromCellMenu

Set ContextMenu = Application.CommandBars("Cell")

Set MySubMenu = ContextMenu.Controls.Add(Type:=msoControlPopup, before:=3)

With MySubMenu
.Caption = "Recruitment"
.Tag = "My_Cell_Control_Tag"

With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & "Rejections"
.FaceId = 97
.Caption = "Format Rejections"
End With
With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & "Hires"
.FaceId = 87
.Caption = "Format Hires"
End With

End With

ContextMenu.Controls(4).BeginGroup = True
End Sub



Sub DeleteFromCellMenu()
Dim ContextMenu As CommandBar
Dim ctrl As CommandBarControl

Set ContextMenu = Application.CommandBars("Cell")

For Each ctrl In ContextMenu.Controls
If ctrl.Tag = "My_Cell_Control_Tag" Then
ctrl.Delete
End If
Next ctrl

On Error Resume Next
ContextMenu.FindControl(ID:=3).Delete
On Error GoTo 0
End Sub


Rejections and Hires are the two macros I'm asking for it to call. These are simple macros that I know work ok so didn't bother adding the code for those.










share|improve this question















I've used the Ron de Bruin tutorial to create a custom right click menu.
This works no problem when using it in an XLSM file type, but when I try to turn this into an Excel Add-in, the right click menu doesn't appear. Is there something specific I need to add in to the code to enable it?



The code I used in 'ThisWorkbook' is:



Private Sub Workbook_Activate()
Call AddToCellMenu
End Sub

Private Sub Workbook_Deactivate()
Call DeleteFromCellMenu
End Sub


The code I used in a separate module is:



Sub AddToCellMenu()
Dim ContextMenu As CommandBar
Dim MySubMenu As CommandBarControl

Call DeleteFromCellMenu

Set ContextMenu = Application.CommandBars("Cell")

Set MySubMenu = ContextMenu.Controls.Add(Type:=msoControlPopup, before:=3)

With MySubMenu
.Caption = "Recruitment"
.Tag = "My_Cell_Control_Tag"

With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & "Rejections"
.FaceId = 97
.Caption = "Format Rejections"
End With
With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & "Hires"
.FaceId = 87
.Caption = "Format Hires"
End With

End With

ContextMenu.Controls(4).BeginGroup = True
End Sub



Sub DeleteFromCellMenu()
Dim ContextMenu As CommandBar
Dim ctrl As CommandBarControl

Set ContextMenu = Application.CommandBars("Cell")

For Each ctrl In ContextMenu.Controls
If ctrl.Tag = "My_Cell_Control_Tag" Then
ctrl.Delete
End If
Next ctrl

On Error Resume Next
ContextMenu.FindControl(ID:=3).Delete
On Error GoTo 0
End Sub


Rejections and Hires are the two macros I'm asking for it to call. These are simple macros that I know work ok so didn't bother adding the code for those.







excel vba excel-vba excel-2010 excel-addins






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 11:25

























asked Nov 19 at 10:34









S. Laycock

12




12












  • Please edit your question and show exactly the code you use in your project (alternatively add a Minimal, Complete, and Verifiable example). Links to similar code are not sufficient we need to see your code (links might break in future and the question becomes useless to other readers). Also note that "it won't work" is no useful error description. Tell us which error you get and in which line or what your code actually does vs. what you expect it to do.
    – Pᴇʜ
    Nov 19 at 10:42








  • 2




    If you're using an add-in, you probably want the Workbook_Open and Workbook_BeforeClose events rather than the Activate/Deactivate ones.
    – Rory
    Nov 19 at 10:51










  • @Rory that seems to have done the trick. The Workbook_BeforeClose command didn't work so I reverted to using deactivate. Thank you.
    – S. Laycock
    Nov 19 at 11:35




















  • Please edit your question and show exactly the code you use in your project (alternatively add a Minimal, Complete, and Verifiable example). Links to similar code are not sufficient we need to see your code (links might break in future and the question becomes useless to other readers). Also note that "it won't work" is no useful error description. Tell us which error you get and in which line or what your code actually does vs. what you expect it to do.
    – Pᴇʜ
    Nov 19 at 10:42








  • 2




    If you're using an add-in, you probably want the Workbook_Open and Workbook_BeforeClose events rather than the Activate/Deactivate ones.
    – Rory
    Nov 19 at 10:51










  • @Rory that seems to have done the trick. The Workbook_BeforeClose command didn't work so I reverted to using deactivate. Thank you.
    – S. Laycock
    Nov 19 at 11:35


















Please edit your question and show exactly the code you use in your project (alternatively add a Minimal, Complete, and Verifiable example). Links to similar code are not sufficient we need to see your code (links might break in future and the question becomes useless to other readers). Also note that "it won't work" is no useful error description. Tell us which error you get and in which line or what your code actually does vs. what you expect it to do.
– Pᴇʜ
Nov 19 at 10:42






Please edit your question and show exactly the code you use in your project (alternatively add a Minimal, Complete, and Verifiable example). Links to similar code are not sufficient we need to see your code (links might break in future and the question becomes useless to other readers). Also note that "it won't work" is no useful error description. Tell us which error you get and in which line or what your code actually does vs. what you expect it to do.
– Pᴇʜ
Nov 19 at 10:42






2




2




If you're using an add-in, you probably want the Workbook_Open and Workbook_BeforeClose events rather than the Activate/Deactivate ones.
– Rory
Nov 19 at 10:51




If you're using an add-in, you probably want the Workbook_Open and Workbook_BeforeClose events rather than the Activate/Deactivate ones.
– Rory
Nov 19 at 10:51












@Rory that seems to have done the trick. The Workbook_BeforeClose command didn't work so I reverted to using deactivate. Thank you.
– S. Laycock
Nov 19 at 11:35






@Rory that seems to have done the trick. The Workbook_BeforeClose command didn't work so I reverted to using deactivate. Thank you.
– S. Laycock
Nov 19 at 11:35



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372731%2fcustom-right-click-menu-excel-add-in-not-loading%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372731%2fcustom-right-click-menu-excel-add-in-not-loading%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?