How to make a Ribbon Control read only in Excel either by CustomUI or VBA

70 Views Asked by At

I need to allow the user to navigate through the characters in the Ribbon input controls so they view them but editing. Currently I use 'onChange' method of the controls to set the value I want so the user can't provide their choice like below.

Sub OnChange(control As IRibbonControl, text As String)
'Workaround to prevent changes for these controls as there is no property like Lock.
If InStr(1, "|id_SelectFileComboBox|id_SelectedFilePathEditBox|", "|" & control.ID & "|", vbTextCompare) Then
  'Ribbon variable stored the Ribbon control by onLoad method of CustomUI
  'Invalidating control so to trigger gettext to result desired value
  Ribbon.InvalidateControl control.ID
End If
End Sub
Sub gettext(control As IRibbonControl, ByRef returnedVal)
If InStr(1, "|id_SelectFileComboBox|id_SelectedFilePathEditBox|", "|" & control.ID & "|", vbTextCompare) Then
  returnedVal = "My desired value"
End If
End Sub

Is there any workaround for this to make the controls read-only?

0

There are 0 best solutions below