Solved Create a keyboard shortcut on a ribbon

zelarra821

Registered User.
Local time
Today, 23:19
Joined
Jan 14, 2019
Messages
834
Hello. I have a custom ribbon in which I add a procedure created by me (with your invaluable help, thanks). I want to know if it is possible to add a keyboard shortcut to it, and where and how it would be done.

Thanks a lot.

Code:
<?xml version="1.0" encoding="utf-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon startFromScratch="true">
<tabs>
<tab id="T001" label="Formato de texto">
<group idMso="GroupTextFormatting">
</group> 
<group id="PegadoEspecial" label="Pegado especial">
<button id="PegarTextoSinFormato" label="Pegar texto sin formato" imageMso="Paste" size="large" supertip="Pegar texto sin formato" onAction="rbPegarSinFormato" />
</group>
</tab> 
</tabs>
</ribbon> 
</customUI>

Code:
Sub rbPegarSinFormato(Control As IRibbonControl)
  
If (Screen.ActiveControl & "") = "" Then
  Screen.ActiveControl = Application.PlainText(Clipboard)
Else
  Screen.ActiveControl = Application.HtmlEncode(Application.PlainText(Screen.ActiveControl & "<br>" & Clipboard))
End If
  
  Dim ctrl As Access.Control
Set ctrl = Screen.ActiveControl
ctrl.SelStart = Len(ctrl.Text)
End Sub
 
What do you mean by ‘adding a keyboard shortcut to it’? Do you mean you want the xml code to execute a shortcut? Or you want a shortcut to do the same thing as clicking the button?
 
I want a shortcut to do the same thing as clicking the button
 
Last edited:
My sub paste text without format when you copy from the internet, for example
 
in that case, would have thought using the control keydown event would be simpler a better way - coding would be along the lines of

XML:
Private Sub mycontrol_KeyDown(KeyCode As Integer, Shift As Integer)

if shift=2 and keycode=vbkeyv then 'ctrl-V
     If mycontrol = "" Then
         mycontrol = Application.PlainText(Clipboard)
     Else
         mycontrol = Application.HtmlEncode(Application.PlainText(mycontrol & "<br>" & Clipboard))
     End If
     mycontrol.SelStart = Len(mycontrol.Text)
end if
end sub

Still not sure why your code is like this - why if the control is "" store as plaintext and if not store as html when you apparently want the format removed
 
Thank you very much for the suggestions. I'm going to go with the second option, instead of an Autokeys macro.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom