View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default CAN I ADD CONTROLX BUTTON TO CUSTOMISED TOOLBARS

This is already supported by the arrow keys.

FYI, for continued execution of a macro, I would take advantage of the fact
that assigning a macro to a keyboard key allows repeated execution while the
key is held down. A macro is continually executed the same way holding down
the "a" key produces a long string of a's ("aaaaaaaaaaaaaa").

I would create the toolbar programmatically on open (which I always do) and
assign the "TogRemap" macro to the desired button. Assumed is that the macros
"Macro1", "Macro2" etc. are your macros. Code examples:

Sub TogRemap()
With Application.CommandBars.ActionControl
If .State = msoButtonUp Then
.State = msoButtonDown
RemapKeys
Else
.State = msoButtonUp
ResetKeys
End If
End With
End Sub

Sub RemapKeys()
With Application
.Cursor = xlNorthwestArrow
.OnKey "{UP}", "Macro1"
.OnKey "{DOWN}", "Macro2"
.OnKey "{LEFT}", "Macro3"
.OnKey "{RIGHT}", "Macro4"
End With
End Sub

Sub ResetKeys()
With Application
.Cursor = xlDefault
.OnKey "{UP}"
.OnKey "{DOWN}"
.OnKey "{LEFT}"
.OnKey "{RIGHT}"
End With
End Sub

Regards,
Greg