Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShortCut Key to work on msoControlButton

Status
Not open for further replies.

2sj

MIS
Apr 5, 2005
9
US
I know how to create a custom menu bar and add controls to it. Say, for instance, I have a control on a popup control. I know I can set the .ShortcutText of the control, but exactly how do I get the shortcut key to work.
for example.

Dim newCtl As CommandBarControl
...
...

With NewCtl
.Caption = "Test"
.ShortcutText = "Ctl+Shift+M"
.OnAction = "Blah"
End With

What do I need to do in order to get the keys Ctl+Shift+M to actually perform "Blah" action?

Thanks. Probably something easy I am missing or forgot...
 
For me, the Office.CommandBarControl object doesn't expose a ShortcutText property ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
The ".ShortCutText" works. It is setup using the
With ctl
.ShortCutText = "Ctrl+Shift+T"
End With
but all these does is setup the text to show in the menu bar. it's just a string. I want to know how to get those combination of keys to actually perform that control button's onaction event.

Below is my code that sets up the control.
Sub Test1()

Dim cbCmdBar As CommandBar
Dim cbCtls As CommandBarControls

Set cbCmdBar = Application.CommandBars.Add("Test Bar", _
msoBarFloating, True, True)

cbCmdBar.Position = msoBarTop

cbCmdBar.Visible = True

'Add controls
Set espCtls = espCmdBar.Controls


Set cbpop = espCtls.Add(Type:=10)
cbpop.Caption = "&Edit"
cbpop.Visible = True


Set cbsub = NewCtl(cbpop, msoControlButton, "&Test", True, 682, "Ctrl+Shift+M", , "cbTest", , "onActionHere")

...
End Sub

Function NewCtl(ByVal cbCtl As CommandBarControl, _
ByVal strType As Integer, _
ByVal strCaption As String, _
ByVal bVisible As Boolean, _
Optional ByVal intIcon As Integer, _
Optional ByVal strShortCut As String, _
Optional ByVal strTip As String, _
Optional ByVal strTag As String, _
Optional ByVal bBeginGrp As Boolean, _
Optional ByVal strAction As String) As CommandBarControl

Dim newCtl As CommandBarControl

Set newCtl = cbCtl.Controls.Add(Type:=strType)

With newCtl
.Caption = strCaption
.Visible = bVisible
.Style = msoButtonIconAndCaption
.FaceId = intIcon
.ShortcutText = strShortCut
.TooltipText = strTip
.Tag = strTag
.BeginGroup = bBeginGrp
.OnAction = "= " & strAction
End With

'NewESPCtl = newCtl

End Function
 
newCtl must be an Office.CommandBarButton object and I guess the OnAction must be defined before ShortcutText.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I gave it a shot. When I created the control button, I set its onaction before setting the ShortcutText. But it still didn't work. Again, the ShortcutText is simply a text/srting property. it has no functionality. I'd imagine I gotta define that the combination of "Ctrl+Shif+M" means to do what the control is meant to do. But not sure how to do that.

Thanks for trying though.
 
Well, I'm creating aCommandBarControl and am quite able to set it's .ShortcutText property. My question actually was how do I make it so that when a person actually hits the key combination of, say, the control + shift+ M keys, it would actually perform the same action as a specific menu bar item. But I figured it out anyways; I just have to create a macro, "Autokeys" and set the key combinations in it. Sorry if my original question was confusing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top