Shortcut Menu

khurram7x

Registered User.
Local time
Today, 19:53
Joined
Mar 4, 2015
Messages
226
I've searched over the internet but more I see, more I'm getting confused about which instruction to follow for the Right-Click Shortcut Menu.

Could someone please guide towards the tested and working code, to do this right and easy way in VBA??

Thanks
 
There is a really good sample here somewhere. I think it was by ChrisO. I'll take a look for it.
 
Thank you. It is a lot of code though. I never thought creating a simple menu with 3 4 options will be that complicated!!
 
I think his code can be trimmed down a lot. What's nice about it is you can use tables to control how the menu is.
 
Here is what I am using just for cut/copy/paste. I think all of this was derived from ChrisO's work. The first part creates the menu object in the database. You can run this from the immediate window first:
Code:
Public Sub CopyCutPaste()
    Dim cmbRC  As CommandBar
    Dim cmbButtonCopy As CommandBarButton
    Dim cmbButtonCut As CommandBarButton
    Dim cmbButtonPaste As CommandBarButton
    Dim strBarName As String
    strBarName = "CopyCutPaste"
    On Error Resume Next
    CommandBars(strBarName).Delete
    On Error GoTo 0
    Set cmbRC = CommandBars.Add(strBarName, msoBarPopup, False)
 
    Set cmbButtonCut = cmbRC.Controls.Add(msoControlButton, 19)
    Set cmbButtonCopy = cmbRC.Controls.Add(msoControlButton, 21)
    Set cmbButtonPaste = cmbRC.Controls.Add(msoControlButton, 22)
 
    'Cleanup
    Set cmbRC = Nothing
    Set cmbButtonCopy = Nothing
    Set cmbButtonCut = Nothing
    Set cmbButtonPaste = Nothing
End Sub

Put this in the load event of any form with this menu:

Code:
Public Sub RightClick(frm As Form)
    On Error GoTo err
    Dim ctl    As control
    For Each ctl In frm.Controls
        If ctl.Enabled = True Then
            If TypeOf ctl Is TextBox Then
                ctl.ShortcutMenuBar = "CopyCutPaste"
            End If
            If TypeOf ctl Is ComboBox Then
                ctl.ShortcutMenuBar = "CopyCutPaste"
            End If
        End If
skip:
    Next ctl
    Exit Sub
err:
    If err.Number = 438 Then Resume skip              'object does not support this property
    ReportError err.Number, err.Description, "mdlMSLRoutines | RightClick"
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom