I use the 'Update' event of CommandBars to determine when controls should be enabled and set various other properties. I also use the 'Execute' event for most of my actions.
I came across the need to "trigger" the Execute event for a control that was not necessarily clicked upon. For instance, I have certain internal shortcut keys that will trigger a command without using KeyBindings (this was done by design since KeyBindings intercepts all shortcut keys). I created the following routine to trigger the execution of a command based on the ID of the command bar control:
Public Sub ExecuteCommandBarControl(ByRef CommandBars As CommandBars, ByVal ID As Long) Dim TempBar As CommandBar, Control As CommandBarControl If CommandBars Is Nothing Then Exit Sub Set TempBar = CommandBars.Add("Temp", xtpBarPopup) Set Control = TempBar.Controls.Add(xtpControlButton, ID, "Temporary") Control.Execute End Sub
This results in the Execute event being fired. The problem is that this temporary control never gets passed to the 'Update' event because it is never shown. Is there a way to force the command to update? If not, would it be possible to add an 'Update' method to the CommandBarControl that would trigger the 'Update' event? Then would allow me to modify the procedure to only execute the control if the control is enabled (as is set in the Update event). In other words, this is what I would like to be able to do:
Public Sub ExecuteCommandBarControl(ByRef CommandBars As CommandBars, ByVal ID As Long) Dim TempBar As CommandBar, Control As CommandBarControl If CommandBars Is Nothing Then Exit Sub Set TempBar = CommandBars.Add("Temp", xtpBarPopup) Set Control = TempBar.Controls.Add(xtpControlButton, ID, "Temporary") Control.Update If Control.Enabled Then Control.Execute End Sub
Thanks in advance.
|