Excel VBA - Intercept AddIn Ribbon Click - excel

i would like to know if it is possible to intercept the event generated by the Ribbon Button of an Excel Addin. I'm able to access to the .xlam source but seems there is no code in it that intercept that event, so I think the handler is in the compiled component. Is my assessment correct? And then, if yes, can I intercept a click on a button of the ribbon, maybe using an Application Level Handler?
Thank you,
DD

The Ribbon button has a callback assigned to its onAction attribute - it will be a Sub in the addin that has an iribboncontrol parameter (or similar). If you have can view the customui part of the add-in's XML you will be able to determine exactly which callback is relevant.

Related

Open directly a web page from a button in Ribbon in a browser outside Excel?

We have several Excel add-ins in AppSource. At the moment, we have a button in Ribbon for Documentation, clicking on the button opens the documentation webpage in a taskpane in Excel.
We feel that as the taskpane is small, people are unlikely to read documentation over there. So a better way would be to open the documentation webpage in a browser outside Excel.
We notice that in Script Lab, clicking on the Reference Docs opens a small window which contains open link in new window. Then, we need to click on that link to finally open that in a browser:
https://user-images.githubusercontent.com/774409/81099107-ab068e80-8f0a-11ea-9633-eba5c1e42f90.png
So do we have to have this intermediate window? Cannot we open directly a web page from a button in Ribbon in a browser outside Excel?
PS: I don't want to use Dialog API to show documentation, because it seems that when the Dialog window is open, we cannot use Excel at the same time?
In manifest, you could make it UI less, and specifies the source code file for operations that an add-in exposes through add-in commands that execute a JavaScript function instead of displaying UI,
<DesktopFormFactor>
<FunctionFile resid="residDesktopFuncUrl" />
<ExtensionPoint xsi:type="PrimaryCommandSurface">
<!-- information about this extension point -->
</ExtensionPoint>
</DesktopFormFactor>
and in the FunctionFile you could add a function, which can call Office.context.ui.openBrowserWindow(url) to launch the URL in the default browser outside of excel
Office.context.ui.openBrowserWindow("https://github.com");
The document can be found at here, which describes how to implement the function defined by FunctionName in the manifest.

Add Solver to Custom Ribbon to Show the Solver Parameters Dialog Box

The goal is to add the standard Solver button to a custom ribbon.
Background: I have code that creates a Solver model automatically using custom ribbon buttons. However, before actually running Solver, I would like the user to verify, and modify as necessary, the automatically-generated Solver model - by showing the Solver Parameters dialog box. For the user's convenience, I want to put the standard Solver button on my custom ribbon.
Problems were:
Solver does not have an official Microsoft msoImage or onAction item. So, I created my own button that called SolverOkDialog(). BUT,...
SolverOkDialog does not display the Solver Parameters dialog box (at least I couldn't get it to do so).
Solution:
Big picture: Grab the icon and link from Solver.xlam.
Copy C:\Program Files (x86)\Microsoft Office\Office15\Library\SOLVER\SOLVER.XLAM to a new file, Solver.zip.
Copy ….zip\customui\images\solver_icon.png to someplace convenient.
Using your favorite ribbon xml editor(1) assign solver_icon to RibbonX14.
Insert the following code to your custom ribbon:
<button id="btnSolver"
getLabel="solver.xlam!GetSolverLabel"
image="solver_icon"
onAction="solver.xlam!MainEx"
screentip="Solver"
supertip="What-if analysis tool that finds the optimal value of a target cell by changing values in cells used to calculate the target cell."/>
I hope this helps someone.
If I am missing something, please let me know.
​(1) I use Leaf Creations Office ​Ribbon Editor because it is simple, functions well, and it is Creative Commons compliant.

Dynamic CRM 2011. Hide/show tabs using radio buttons issue

I have this code that hides tabs and shows tabs in CRM 2011. By default all tabs are hidden, but when the client has the product purchased (yes selected), the tab is showen.
The issue I am having is when I click yes and save & close. Then reopen the account, the tab is hidden, but the option is still yes.
The code is:
function showTab(tabNumber, optionField, optionValue) {
if (Xrm.Page.getAttribute(optionField).getValue() == optionValue) {
Xrm.Page.ui.tabs.get(tabNumber).setVisible(true);
}
else {
Xrm.Page.ui.tabs.get(tabNumber).setVisible(false);
}
}
The option I have is:
2,"new_server",'1'
I got the code from this place:
Show a Tab Dynamics CRM 2011
I am still working on this.
You need to register this function on both the form's OnLoad event and the field's OnChange event. It sounds, from your description, that it is registered and working for the OnChange event but the OnLoad event.
You currently have the function registered on the onChange event for the radio button control.
Additionally, you need to register an onLoad event for the form.
Create a new web resource.
Open Form Properties.
Add form to available resources.
Add event handler onLoad, and call your webresource.
In the web resource you can just have a call to your showTab function.
When you open the form for customization, look at the top ribbon of the form. You will see Form Properties icon right next to Preview. Click on Form Properties and then add the JavaScript web resource in the Form Library.
Choose Event: OnLoad from the drop down and then click add under the Event Handler.
Choose the web resource of your choice, add the function name being used in your code (showTab).
This will add the function to your Onload event of the form.

VB.NET Update User Control Immediately When UI Editor Changes

I have a User Control in VB.NET (VS 2010) inherited from a picturebox. I also have a class that holds 40 or so properties for the control. I also have a form with a property grid that is used as an editor. The editor form opens when clicking the "Custom" property of the control in the IDE. On the form are an OK and Cancel button which either saves or discards changes.
All of this works fine, but I need to have my control "refresh" when a property changes in the grid. The property grid has an event for this, but I don't know how to call or invoke my sub in the control to essentially repaint the control. If I call the sub directly nothing refreshes on the control until after I close the editor form (dialog). Is there a way to have the control repaint/redraw with the editor dialog still open?
Thanks,
EluZioN
Try using Context.Instance which is passed when your UI_Editor is invoked. In the GetEditStyle override, a Context object is passed. This holds a reference to the calling UserControl.
I do something like this (CUSTOM UI_TYPE_EDITOR):
Dim ContextOBJ as MyUserControl
Public Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext)......
contextOBJ = CType(context.Instance, MyUserControl)
In the GetEditValue override, you can call ContextOBJ.Refresh and your UserControl should immediately reflect any changes. It works for me.

Accessing Ribbon Controls Programatically in an XML Ribbon

For programming Office Add-ins using C# 4.0, Microsoft provides two different ways of creating and/or modifying the Ribbon interface: you can use the Ribbon Designer or define the Ribbon's layout in Ribbon XML.
If you create a ribbon using the Ribbon designer, the class generated in the code behind has visibility to all the controls you've placed on the ribbon. So if I've placed a RibbonDropDown called "dropdown1", I could use the following code to add an item to it:
RibbonDropDownItem item = Factory.CreateRibbonDropDownItem();
item.Label = submatrix.Name;
item.Tag = submatrix;
this.dropDown1.Items.Add(item);
However, if you create the same Ribbon using Ribbon XML, dropDown1 or Factory aren't found ("The name does not exist in the current context").
Is there a way to access the items added to a Ribbon XML-defined ribbon in code?
Might be a little late, but hopefully this helps someone.
I was utterly confused about this same issue. Turns out, you can only access these controls as string ids, and the model is heavy on invalidation events. So for example, when you get a button click via onAction method, you only have the sender's id from the control object, however, in this event handler, you can invalidate the other controls and have their events called using
ribbon.InvalidateControl("MyCtl");
check out this MS Lab, it has everything you need to get up and running

Resources