Refreshing Custom Ribbon Tab in Excel 2010 When Someone Clicks on the Tab - vsto

I've been writing a custom ribbon with VSTO (using VB.net and XML) and I have written a number of buttons who's labels & pressed states depend on the calculation mode that Excel is in.
The getPressed and getLabels callback functions check for the excel calculation mode but these are only called when the ribbon is first loaded or the buttons are clicked. If someone were to go into the "formulas" tab, change the calculation mode and then go back to the custom ribbon tab, the pressed states and labels on the buttons in this custom tab would now be incorrect.
Is there a way to trigger these callback functions to be called (eg a way to call the ribbon.invalidate() function) when someone clicks on the custom ribbon tab in Excel?

Related

Under Excel O365, the custom ribbon tab does not always populate

Using an .xlam project with a fully working custom ribbon, I have found that the new tab will sometimes show nothing when clicked on. It is intermittent. The global RibbonUI object is available and running an .invalidate will then show the ribbon. However, the .invlalidate attempts prior to the tab being viewed do not seem to change this behavior. I have to view the tab and then run the .invalidate manually (with a macro button) to see the ribbon appear.
I am scratching my head trying to find a slick way of making this new custom tab populate 100% of the time.
For the benefit of those that come across this issue, I have found the root cause and a solution. This is Excel O365 specific.
If you have a custom ribbon tab set up and working, try this. Open Excel, create a blank workbook, then double-click on a cell to put it in "edit mode". Click on your custom ribbon tab. Blank, right?
This "cell in edit mode" is what was causing Excel O365 to fail to show my custom ribbon. Excel O365 starts up on the "File" screen. Prior versions always opened to a blank sheet. If you click on "Blank workbook", the ribbon displays fine. If you DOUBLE-CLICK on "Blank workbook", the first click opens the workbook and the second click puts a cell into ""edit mode". In this state, clicking on your custom ribbon tab shows nothing.
The work-around
Private Sub WorkbookActivate(ByVal Wb As Workbook)
Application.SendKeys "{ESC}"
...
You may see a cell go into edit mode for one blink but it then exits edit mode. Click on your custom ribbon tab. It will now show the ribbon controls as designed.

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.

Lock ribbon button in VB.NET

I am developing a application in VB.NET. The user interface contains a ribbon tab with a few ribbon buttons. On each ribbon button click event, the application will execute a process.
When a process being executed, I want to lock the click event of other ribbon buttons. It means, the user should not be able to pick the other ribbon buttons.
I do not find the lock property for ribbon buttons. To avoid the button getting grey, I do not want to disable the button. please provide your suggestion.

In Excel, is there a way to determine the method being called by a password protected 3rd-party ribbon button?

I'm looking to automate a simple process in VBA and need to "click" a ribbon button. It makes the most sense to just call the button's underlying method. Is there a way to figure out what it is?
We are using Excel 2007 and 2010.
If it's Excel 2003 or earlier, you can use the CommandbarControl.Execute method. For instance:
Application.Commandbars("3rd Party Toolbar").Controls("Button to Push").Execute
There are two ways you can do this.
Right click on the toolbar and select Customise. If you right click on the button there may be details somewhere of what Macro the button is associated with.
If you record a macro and click the button. Then you can look at the VBA workspace and view the code that is generated to run your macro (which is just clicking the button you want). This will show you what method the macro clicks.

Vba button to activate sheet

I am trying to write the callback for a button on the backstage view.
I want to select a certain worksheet and show it to the user. I thought aboutsheet("sheetName").activate. This is selecting the sheet sheetName, but Excel stays in backstage view.
My question is how can I actually show the sheet, i.e. make it visible? I need to be able to hide backstage view and go to "document view"...
Regards
Add the attribute isDefinitive="true" to the ribbon backstage button xml. It will close the backstage view after the button is clicked and switch back to the main view with the previous tab selected.