Excel VSTO addin, custom popup menu on right click using XML ribbon
In my VSTO addin, I pop a custom menu if someone right clicks a cell containing a valid bond CUSIP (finance industry jargon for a bond id). The method below accomplishes this using CommandBars. The question I have is how to accomplish the same using XML ribbon definitions.
Here is the current code using command bars (works fine):
private static Office.CommandBar cbBondPopup = null;
private void Application_SheetBeforeRightClick(object Sh, Excel.Range Target, ref bool Cancel)
{
Cancel = false; // overridden to true by btn1, btn2, btn3 handlers below (so that Excel Cell Menu is cancelled)
if (IsBondCusip(this.Application.ActiveCell.Value2))
{
if (cbBondPopup == null && IsBondCusip(this.Application.ActiveCell.Value2))
{
// create command bar if nec
cbBondPopup = this.Application.CommandBars.Add(Name: "BondMenu", Position: Office.MsoBarPosition.msoBarPopup, Temporary: true);
// define 3 custom buttons
var btn1 = (Office.CommandBarButton)cbBondPopup.Controls.Add(Type: Office.MsoControlType.msoControlButton, Temporary: true);
var btn2 = (Office.CommandBarButton)cbBondPopup.Controls.Add(Type: Office.MsoControlType.msoControlButton, Temporary: true);
var btn3 = (Office.CommandBarButton)cbBondPopup.Controls.Add(Type: Office.MsoControlType.msoControlButton, Temporary: true);
btn1.Caption = "Bond Summary"; btn2.Caption = "Bond Details"; btn3.Caption = "Find Similar Bonds";
// connect buttons to handlers ==> CmdBarEventHndlr(CommandBarButton Ctrl, ref bool Cancel)
btn1.Click += Click_BondSummary; btn2.Click += Click_BondDetails; btn3.Click += Click_FindSimilarBonds;
}
cbBondPopup.ShowPopup(); // pop bond menu (handlers set Cancel to true so Excel Cell Menu is cancelled unless user hits ESC)
}
}
Next, here are the same buttons defined in XLM ribbon syntax. In this case the onAction methods have a different signature - e.g. Click_BondSummary(Office.IRibbonControl ctrl).
<button id="btnBondSummary" label="BondSummary" onAction="Click_BondSummary"/>
<button id="btnBondDetails" label="BondDetails" onAction="Click_BondDetails"/>
<button id="btnFindBonds" label="FindBonds" onAction="Click_FindSimilarBonds"/>
I was hoping I could just put these definitions into an XML context menu and pop that. By setting idMso="ContextMenuCell" I can cause the buttons to show up in the Excel Cell menu itself - but that's not what I want. I want them to pop up in their own standalone popup menu.
QUESTION: Is there a way to rewrite my right-click handler using XML ribbon button definitions instead of command bars? (Otherwise I need two definitions of everything - one for the ribbon and one for the command bar popup).
c# vsto ribbonx
add a comment |
In my VSTO addin, I pop a custom menu if someone right clicks a cell containing a valid bond CUSIP (finance industry jargon for a bond id). The method below accomplishes this using CommandBars. The question I have is how to accomplish the same using XML ribbon definitions.
Here is the current code using command bars (works fine):
private static Office.CommandBar cbBondPopup = null;
private void Application_SheetBeforeRightClick(object Sh, Excel.Range Target, ref bool Cancel)
{
Cancel = false; // overridden to true by btn1, btn2, btn3 handlers below (so that Excel Cell Menu is cancelled)
if (IsBondCusip(this.Application.ActiveCell.Value2))
{
if (cbBondPopup == null && IsBondCusip(this.Application.ActiveCell.Value2))
{
// create command bar if nec
cbBondPopup = this.Application.CommandBars.Add(Name: "BondMenu", Position: Office.MsoBarPosition.msoBarPopup, Temporary: true);
// define 3 custom buttons
var btn1 = (Office.CommandBarButton)cbBondPopup.Controls.Add(Type: Office.MsoControlType.msoControlButton, Temporary: true);
var btn2 = (Office.CommandBarButton)cbBondPopup.Controls.Add(Type: Office.MsoControlType.msoControlButton, Temporary: true);
var btn3 = (Office.CommandBarButton)cbBondPopup.Controls.Add(Type: Office.MsoControlType.msoControlButton, Temporary: true);
btn1.Caption = "Bond Summary"; btn2.Caption = "Bond Details"; btn3.Caption = "Find Similar Bonds";
// connect buttons to handlers ==> CmdBarEventHndlr(CommandBarButton Ctrl, ref bool Cancel)
btn1.Click += Click_BondSummary; btn2.Click += Click_BondDetails; btn3.Click += Click_FindSimilarBonds;
}
cbBondPopup.ShowPopup(); // pop bond menu (handlers set Cancel to true so Excel Cell Menu is cancelled unless user hits ESC)
}
}
Next, here are the same buttons defined in XLM ribbon syntax. In this case the onAction methods have a different signature - e.g. Click_BondSummary(Office.IRibbonControl ctrl).
<button id="btnBondSummary" label="BondSummary" onAction="Click_BondSummary"/>
<button id="btnBondDetails" label="BondDetails" onAction="Click_BondDetails"/>
<button id="btnFindBonds" label="FindBonds" onAction="Click_FindSimilarBonds"/>
I was hoping I could just put these definitions into an XML context menu and pop that. By setting idMso="ContextMenuCell" I can cause the buttons to show up in the Excel Cell menu itself - but that's not what I want. I want them to pop up in their own standalone popup menu.
QUESTION: Is there a way to rewrite my right-click handler using XML ribbon button definitions instead of command bars? (Otherwise I need two definitions of everything - one for the ribbon and one for the command bar popup).
c# vsto ribbonx
Yes, as long as it's Office 2010 or newer. The basic information can be found at docs.microsoft.com/en-us/previous-versions/office/developer/… and docs.microsoft.com/en-us/visualstudio/vsto/…
– Cindy Meister
Nov 27 '18 at 14:52
I may be overlooking it, but I don't see any explanation of creating a custom context menu from scratch. Lots of examples about adding custom options to existing mso context menus, but not exactly the same.
– tpascale
Nov 29 '18 at 16:32
add a comment |
In my VSTO addin, I pop a custom menu if someone right clicks a cell containing a valid bond CUSIP (finance industry jargon for a bond id). The method below accomplishes this using CommandBars. The question I have is how to accomplish the same using XML ribbon definitions.
Here is the current code using command bars (works fine):
private static Office.CommandBar cbBondPopup = null;
private void Application_SheetBeforeRightClick(object Sh, Excel.Range Target, ref bool Cancel)
{
Cancel = false; // overridden to true by btn1, btn2, btn3 handlers below (so that Excel Cell Menu is cancelled)
if (IsBondCusip(this.Application.ActiveCell.Value2))
{
if (cbBondPopup == null && IsBondCusip(this.Application.ActiveCell.Value2))
{
// create command bar if nec
cbBondPopup = this.Application.CommandBars.Add(Name: "BondMenu", Position: Office.MsoBarPosition.msoBarPopup, Temporary: true);
// define 3 custom buttons
var btn1 = (Office.CommandBarButton)cbBondPopup.Controls.Add(Type: Office.MsoControlType.msoControlButton, Temporary: true);
var btn2 = (Office.CommandBarButton)cbBondPopup.Controls.Add(Type: Office.MsoControlType.msoControlButton, Temporary: true);
var btn3 = (Office.CommandBarButton)cbBondPopup.Controls.Add(Type: Office.MsoControlType.msoControlButton, Temporary: true);
btn1.Caption = "Bond Summary"; btn2.Caption = "Bond Details"; btn3.Caption = "Find Similar Bonds";
// connect buttons to handlers ==> CmdBarEventHndlr(CommandBarButton Ctrl, ref bool Cancel)
btn1.Click += Click_BondSummary; btn2.Click += Click_BondDetails; btn3.Click += Click_FindSimilarBonds;
}
cbBondPopup.ShowPopup(); // pop bond menu (handlers set Cancel to true so Excel Cell Menu is cancelled unless user hits ESC)
}
}
Next, here are the same buttons defined in XLM ribbon syntax. In this case the onAction methods have a different signature - e.g. Click_BondSummary(Office.IRibbonControl ctrl).
<button id="btnBondSummary" label="BondSummary" onAction="Click_BondSummary"/>
<button id="btnBondDetails" label="BondDetails" onAction="Click_BondDetails"/>
<button id="btnFindBonds" label="FindBonds" onAction="Click_FindSimilarBonds"/>
I was hoping I could just put these definitions into an XML context menu and pop that. By setting idMso="ContextMenuCell" I can cause the buttons to show up in the Excel Cell menu itself - but that's not what I want. I want them to pop up in their own standalone popup menu.
QUESTION: Is there a way to rewrite my right-click handler using XML ribbon button definitions instead of command bars? (Otherwise I need two definitions of everything - one for the ribbon and one for the command bar popup).
c# vsto ribbonx
In my VSTO addin, I pop a custom menu if someone right clicks a cell containing a valid bond CUSIP (finance industry jargon for a bond id). The method below accomplishes this using CommandBars. The question I have is how to accomplish the same using XML ribbon definitions.
Here is the current code using command bars (works fine):
private static Office.CommandBar cbBondPopup = null;
private void Application_SheetBeforeRightClick(object Sh, Excel.Range Target, ref bool Cancel)
{
Cancel = false; // overridden to true by btn1, btn2, btn3 handlers below (so that Excel Cell Menu is cancelled)
if (IsBondCusip(this.Application.ActiveCell.Value2))
{
if (cbBondPopup == null && IsBondCusip(this.Application.ActiveCell.Value2))
{
// create command bar if nec
cbBondPopup = this.Application.CommandBars.Add(Name: "BondMenu", Position: Office.MsoBarPosition.msoBarPopup, Temporary: true);
// define 3 custom buttons
var btn1 = (Office.CommandBarButton)cbBondPopup.Controls.Add(Type: Office.MsoControlType.msoControlButton, Temporary: true);
var btn2 = (Office.CommandBarButton)cbBondPopup.Controls.Add(Type: Office.MsoControlType.msoControlButton, Temporary: true);
var btn3 = (Office.CommandBarButton)cbBondPopup.Controls.Add(Type: Office.MsoControlType.msoControlButton, Temporary: true);
btn1.Caption = "Bond Summary"; btn2.Caption = "Bond Details"; btn3.Caption = "Find Similar Bonds";
// connect buttons to handlers ==> CmdBarEventHndlr(CommandBarButton Ctrl, ref bool Cancel)
btn1.Click += Click_BondSummary; btn2.Click += Click_BondDetails; btn3.Click += Click_FindSimilarBonds;
}
cbBondPopup.ShowPopup(); // pop bond menu (handlers set Cancel to true so Excel Cell Menu is cancelled unless user hits ESC)
}
}
Next, here are the same buttons defined in XLM ribbon syntax. In this case the onAction methods have a different signature - e.g. Click_BondSummary(Office.IRibbonControl ctrl).
<button id="btnBondSummary" label="BondSummary" onAction="Click_BondSummary"/>
<button id="btnBondDetails" label="BondDetails" onAction="Click_BondDetails"/>
<button id="btnFindBonds" label="FindBonds" onAction="Click_FindSimilarBonds"/>
I was hoping I could just put these definitions into an XML context menu and pop that. By setting idMso="ContextMenuCell" I can cause the buttons to show up in the Excel Cell menu itself - but that's not what I want. I want them to pop up in their own standalone popup menu.
QUESTION: Is there a way to rewrite my right-click handler using XML ribbon button definitions instead of command bars? (Otherwise I need two definitions of everything - one for the ribbon and one for the command bar popup).
c# vsto ribbonx
c# vsto ribbonx
edited Nov 27 '18 at 14:38
Cindy Meister
15.4k102235
15.4k102235
asked Nov 26 '18 at 23:47
tpascaletpascale
1,43141937
1,43141937
Yes, as long as it's Office 2010 or newer. The basic information can be found at docs.microsoft.com/en-us/previous-versions/office/developer/… and docs.microsoft.com/en-us/visualstudio/vsto/…
– Cindy Meister
Nov 27 '18 at 14:52
I may be overlooking it, but I don't see any explanation of creating a custom context menu from scratch. Lots of examples about adding custom options to existing mso context menus, but not exactly the same.
– tpascale
Nov 29 '18 at 16:32
add a comment |
Yes, as long as it's Office 2010 or newer. The basic information can be found at docs.microsoft.com/en-us/previous-versions/office/developer/… and docs.microsoft.com/en-us/visualstudio/vsto/…
– Cindy Meister
Nov 27 '18 at 14:52
I may be overlooking it, but I don't see any explanation of creating a custom context menu from scratch. Lots of examples about adding custom options to existing mso context menus, but not exactly the same.
– tpascale
Nov 29 '18 at 16:32
Yes, as long as it's Office 2010 or newer. The basic information can be found at docs.microsoft.com/en-us/previous-versions/office/developer/… and docs.microsoft.com/en-us/visualstudio/vsto/…
– Cindy Meister
Nov 27 '18 at 14:52
Yes, as long as it's Office 2010 or newer. The basic information can be found at docs.microsoft.com/en-us/previous-versions/office/developer/… and docs.microsoft.com/en-us/visualstudio/vsto/…
– Cindy Meister
Nov 27 '18 at 14:52
I may be overlooking it, but I don't see any explanation of creating a custom context menu from scratch. Lots of examples about adding custom options to existing mso context menus, but not exactly the same.
– tpascale
Nov 29 '18 at 16:32
I may be overlooking it, but I don't see any explanation of creating a custom context menu from scratch. Lots of examples about adding custom options to existing mso context menus, but not exactly the same.
– tpascale
Nov 29 '18 at 16:32
add a comment |
0
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',
autoActivateHeartbeat: false,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53490772%2fexcel-vsto-addin-custom-popup-menu-on-right-click-using-xml-ribbon%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53490772%2fexcel-vsto-addin-custom-popup-menu-on-right-click-using-xml-ribbon%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Yes, as long as it's Office 2010 or newer. The basic information can be found at docs.microsoft.com/en-us/previous-versions/office/developer/… and docs.microsoft.com/en-us/visualstudio/vsto/…
– Cindy Meister
Nov 27 '18 at 14:52
I may be overlooking it, but I don't see any explanation of creating a custom context menu from scratch. Lots of examples about adding custom options to existing mso context menus, but not exactly the same.
– tpascale
Nov 29 '18 at 16:32