I was mucking around with some changes to my code - one of which required me to set one of the button ID's to a specific value. Here is my ribbon code
Code:
Option Explicit
Dim bButtonClicked As Boolean
Dim rxIRibbonUI As IRibbonUI
'Dim subtotal_control As IRibbonControl
'Callback for customUI.onLoad
Private Sub rxIRibbonUI_onLoad(ribbon As IRibbonUI)
Set rxIRibbonUI = ribbon
' Get whether we've saved the workbook with or without subtotals
bButtonClicked = Range("Subtotals_exist").Value
End Sub
'Callback for rxlblFeedback getLabel
Private Sub rxlblFeedback_getLabel(control As IRibbonControl, ByRef returnedVal)
Select Case bButtonClicked
Case True
returnedVal = "Remove subtotals"
Case False
returnedVal = "Create subtotals"
End Select
End Sub
'Callback for rxbtnProcess getImage
Private Sub rxbtnProcess_getImage(control As IRibbonControl, ByRef returnedVal)
Select Case bButtonClicked
Case True
returnedVal = "OutlineUngroup"
Case False
returnedVal = "OutlineGroup"
End Select
End Sub
'Callback for Toggle_subtotals onAction
Sub Toggle_subtotals_click(control As IRibbonControl)
Select Case bButtonClicked
Case True
' They've inserted subtotals - remove then
bButtonClicked = False
Range("Subtotals_exist").Value = 0
Application.ScreenUpdating = False
Call Module1.remove_subtotals("")
Application.ScreenUpdating = True
Case False
' Insert subtotals
bButtonClicked = True
Range("Subtotals_exist").Value = 1
Application.ScreenUpdating = False
Call Module1.create_outline_groups("")
Application.ScreenUpdating = True
End Select
' Invalidate the control so that the label/icon are updated
rxIRibbonUI.InvalidateControl (control.ID)
End Sub
'Callback for UpdateButton onAction
Private Sub update_data_ribbon(control As IRibbonControl)
Call Module1.clear_sheet1("")
End Sub
Private Sub update_db_cr_details(control As IRibbonControl)
Call Module1.import_db_cr_details("")
End Sub
Private Sub update_account_structure_details(control As IRibbonControl)
Call Module1.import_account_structure("")
End Sub
Sub refresh_subtotal_ribbon(dummy As String)
bButtonClicked = Range("Subtotals_exist").Value
' Invalidating the control will automatically result in it being updated
rxIRibbonUI.InvalidateControl ("Toggle_subtotals")
End Sub
The actuL VBA code I'm running is as follows:-
Code:
Sub import_account_structure(dummy As String)
Dim sw_error As Boolean
If Range("Subtotals_exist").Value = 1 Then
' They've created subtotals - remove them.
' We MUST set the named range for whether subtotals have been created or not
' to FALSE. That way, the code in refresh_subtotal_ribbon will get it and
' set the variable bButtonClicked to false. That in turn means that ..... ???????
Range("Subtotals_exist").Value = 0
Call Ribbon_modules.refresh_subtotal_ribbon("")
End If
Application.ScreenUpdating = False
Call import_new_data(1, "Koncernstructure.xlsx", sw_error)
If sw_error = True Then
Application.ScreenUpdating = True
Exit Sub
End If
' Remove any bold cells
Columns("A:A").Select
Selection.Font.Bold = False
' and ensure the outline is removed
Selection.ClearOutline
'
' Sort the columns as per "normal"
Call sort_sheet1
Range("A1").Select
Application.ScreenUpdating = True
End Sub
What I'm having difficulty in getting into my head/understanding is what routines are run as a result of the call to
Code:
rxIRibbonUI.InvalidateControl ("Toggle_subtotals")
in refresh_subtotal_ribbon.
I'm assuming (since I now seem to have it working) that the rxlblFeedback_getLabel and rxbtnProcess_getImage are run, but is there any
documentation where I can look to see if others are run ? (Out of interest, I tried adding a MSGBOX call at the start of both rxlblFeedback_getLabel/rxbtnProcess_getImage. All that happened was that the ribbon option disappeared completely as an option. Debug.print
seemed to be okay though)
Bookmarks