Enable/Disable ribbon button from Form - vb.net

Hi I've Windows form with checkbox. I would like enable/disable single button attach into my ribbon. Wound somebody show me a right way?
Part of XML code Ribbon looks like this
<tab idMso="TabNewMailMessage">
<group id="Kompresja2"
label="Lab1">
<toggleButton id="Kompresja6"
imageMso="Smile"
onAction="ProcedureX"
getPressed="Wcisnieto"
getEnabled="Czytaj_stan"
label="Lab2"
size="large"
/>
</group>
</tab>

The getEnabled callback function (in your case Czytaj_stan) checks to see if the button is enabled or not - returns True if the button should
be enabled, False if not.
The getEnabled callback function is called whenever the ribbon-control is invalidated, which is whenever the office application decides it is needed, e.g. when it has been minimized, or when you make it by calling [IRibbonUI-object].InvalidateControl("Kompresja6") to invalidate just that control or [IRibbonUI-object].Invalidate() to redraw the whole ribbon ([IRibbonUI-object].InvalidateControlMso("ID") invalidates a built-in control).
The reference to the IRibbonUI-object needs to be set when the custom ribbon loads.
In order to make this work you need to:
Make sure you can get the reference to the IRibbonUI-object by adding an onLoad callback function in your customUI XML-tag: <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">.
Implement he Ribbon_Load callback function and set a reference to the IRibbonUI-parameter.
Implement the getEnabled function Czytaj_stan to decide when the button should be enabled or not.
Have your form-button first modify the conditions for enabled/disabled in Czytaj_stan, then call [IRibbonUI-object].InvalidateControl("Kompresja6") to invalidate the ribbon-button.

Related

VBA get parameters from IRibbonUI

So I have a custom ribbon that looks something like
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="RibbonLoadFunc" >
and a function
Private Sub RibbonLoadFunc(Ribbon As IRibbonUI)
MsgBox "Hello World"
End Sub
So when I open the document, it prints "Hello World" on the screen as expected. Now, my question is since a reference to IRibbonUI is passed into the function, can I get values of fields of underlying elements? Since the ribbon is defined as an XML document, I would imagine I should be able to access all elements within said document. So, for instance, if I also had
<tab id="myTab">
<group id="myGroup">
<button id="myButton" onAction="someAction" label="someLabel"/>
</group>
</tab>
Is there a way to print the label of myButton, "someLabel", instead of "Hello World"?
Alternatively, is there a way to pass constants into the onLoad function of a IRibbonUI?
This question borders on being too broad and you'd really need to do some extensive research on working with Ribbon XML. Microsoft has done a pretty good job of hiding its documentation since the release of the new JS APIs, so I compiled a list of links and posted it in the MSDN forums: https://social.msdn.microsoft.com/Forums/office/en-US/ba8c9d0b-7312-4503-8167-f2ef86f17435/information-on-the-office-fluent-ui-ribbon-for-developers?forum=officegeneral. I recommend you start with the 3-part series on "Customizing the Office 2007 Fluent UI for developers".
In a nutshell, though, the Ribbon UI interacts with code via "callbacks" - all interaction must be started by the Ribbon, itself. There's no way to "query" the Ribbon object and its controls as you're accustomed to doing using VBA. The VSTO extensions do provide this, as long as the Ribbon you want only requires things supported by its Ribbon Designer. But in the background that works more or less the way I describe below.
Your RibbonLoadFunc is such a callback. It's usually used to assign the Ribbon to a "global" RibbonUI object in your VBA module. Using that, you can at any time trigger the Invalidate or InvalidateControl methods.
At the same time RibbonLoadFunc is triggered when the Ribbon is loaded, the "get" attributes of other controls are triggered. These are used to dynamically populate things like labels and images. If you want to change these dynamic settings at some point, that's when Invalidate or InvalidateControl come into play - they force the "get" callbacks to run.
You can also use these "get" callbacks to populate additional global objects with information about the controls, so that you can use that information "outside" the Ribbon environment.
And that's basically the answer to your question: You can't use the RibbonLoadFunc to access and display information about other Ribbon controls. But the same "loading" that triggers RibbonLoadFunc can also provide information on any controls that have the corresponding "get" callbacks for what you want to "know".
For example, if you had the getLabel="SubInVBA" attribute in the XML for the button, that can dynamically assign the label to the button and at the same time store that information in a global variable and display it (any time you want, from the variable) in a MsgBox.

Invalidate ribbon control in Excel 2013 for multiple workbooks

I have a customized ribbon where I added a tab containing a toggle button. This toggle button has a getPressed attribute which is linked to a callback function returning the pressed state of the toggle button. The purpose of the toggle button is to display/hide a custom task pane. This works fine.
However, my issue is that in Excel 2013, if I have two or more workbooks open, when I invalidate the toggle button, only the one of the active workbook is updated. I also want to update the pressed state of the toggle buttons on the other workbooks as the custom task pane is either visible or invisible in all workbooks.
Anyone knows how to do invalidate a control in the ribbon of all workbooks in Excel 2013?
I am using vb.net and excel-dna.
The toggle button is defined like that:
<toggleButton id="toggleButtonInputData" size="large" onAction="rxToggleButton_onAction" getPressed="rxToggleButton_getPressed" getImage="rxButton_GetImage" getLabel="rxbutton_GetLabel" getEnabled="rxGenericControl_GetEnabled" visible="true"/>
The callback function is:
Function rxToggleButton_GetPressed(ctl As CustomUI.IRibbonControl) As Object
Select Case ctl.Id
Case "toggleButtonInputData"
Return CTP_InputData.IsToggleButtonPressed
End Select
End Function
To invalidate the toggle button I use :
Public Sub CTP_InputData_VisibleStateChange() Handles CTP_InputData.VisibleStateChange
XLRibbon.myRibbon.InvalidateControl("toggleButtonInputData")
End Sub
The Invalidation is only processed for the active workbook's ribbon. But when you then switch to another workbook, the callbacks will fire again and will now be applied to the ribbon of the new workbook.
There's a bug and some quirks in Excel 2013 related to this switching:
If you click on the title bar or the ribbon of the workbook you want to activate, everything works as expected. But if you click on a cell in the workbook you're activating, you get two callbacks - the first is applied to the deactivating workbook's ribbon, and the second is applied to the activating workbook's ribbon. The problem is that you cannot distinguish (in your callback) whether you are getting called for the deactivating book. (Using COM events doesn't help either, both callbacks happen after all the COM Workbook- and Window- (De)Activate events have fired.
Apart from this quirky behaviour, one clear bug in Excel 2013 is that the IRibbonControl.Context is not set to the correct window - in both of the callbacks it reflects the activating window, though the first callback will be applied to the deactivating window.
Here's a detailed discussion on the issue: https://social.msdn.microsoft.com/Forums/windowsserver/en-US/a3dade87-1df7-46ec-8876-437194d7553e/how-to-reference-the-correct-workbook-from-a-control-in-a-ribbon-callback?forum=exceldev
In summary, you don't have good control over the state of deactivated ribbons. But if you are only worried about the active ribbon, Invalidate works fine, but you must expect the callback only upon activation.

Primefaces p:fileUpload add onClick functionality

I want to start p:poll when user click on upload button on p:fileUpload
NOTE: when i put manually onclick script into the button using browser elements works fine. i want to do that same
Basically when the user clicks on the upload button the onstart event is fired so you can use it.
<p:fileUpload onstart="PF('pollWV').start()" />

Visual Basic 2010 Event Listeners on a List

I have a list of buttons in VB2010.
What is the best way to assign a function to their click event.
So every button has the same function, e.g.:
On Button Click
FireFunction(1)
End On Button Click
Without having to add a click event for every button.
The goal is to produce something similar to what is done with the Control Array idea in Visual Basic 2006.
Define a click function as in:
http://visualbasic.about.com/od/learnvbnet/a/eventhandler.htm
and react based on Sender. There may be a cleaner way to setup delegates in VB.NET, but I use it not.

MS Office Excel Ribbon - Cannot change/hide Editing group in Home tab

I have a .net addin for Excel. The addin creates the Ribbon UI for Excel 2007 and re-purposes some existing commands such as Cut, Copy, Paste, Sort etc.
For Cut, Copy and Paste I am just overriding their OnAction value to call my own procedure when the buttons are clicked. But for Sort, Sort Asc and Sort Desc commands the case is a little different. When either of the Sort, Sort Asc or Sort Desc buttons are clicked, I want to get notified and then call the default functionality. This was possible in Excel 2003 commandsbars by calling the Execute() method on the CommandBarControl.
In Excel 2007, there is a ExecuteMso() method to programmatically click a ribbon element but when the OnAction is overridden, this ExecuteMso() method just executes my own procedure and not the default functionality of that button.
So I thought that I will HIDE the Sort buttons in the "Editing" group in Home tab and add my own Sort, Sort Asc and Sort Desc buttons to it. The buttons will call into my procedure first from where I will call the default behavior.
Now the problem is that I am unable to change/hide the Editing group (idMso="GroupEditing"). Is this built-in group not editable? I can however HIDE the Clipboard and other groups(but can't add buttons to them).
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab idMso="TabHome">
<group idMso="GroupEditing" visible="false" />
</tab>
</tabs>
</ribbon>
</customUI>
I think the idMso is incorrect in relation to hiding the Editing group.
idMso="GroupEditingExcel"