Right click menu USER FORM

lbargers

New Member
Joined
Mar 28, 2006
Messages
27
Hi all,

I have some custom VBA functionality built behind an excel worksheet. One of the features that is included is a user form that pops up when a user changes the values of certain fields. A text box on the user form will capture data that is entered by a tester, I would like to allow the testers to have the ability to copy and paste cell data into the text box on the on the user form. Currently this is only possible to paste copied data into this box using the shortcut key (Ctrl-V).

I would a like a small window or menu to appear when a tester right clicks in text box to allow them to copy or paste to this field using the mouse.


Thanks in advance for any help on this issue..

Larry
 
Tom,

Unless I am missing something here but there really is no need for API functions in order to have a textbox context menu.

Here is a rough example :

Code:
Option Explicit


Private Sub TextBox1_MouseDown(ByVal Button As Integer, _
  ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Dim objCmb As CommandBar
    If Button = 2 Then
        Set objCmb = Application.CommandBars.Add(Position:=msoBarPopup)
        With objCmb
            With .Controls.Add(msoControlButton)
                .Caption = "Copy from Clipboard"
                .OnAction = "Copy_from_Clipboard"
            End With
        End With
        objCmb.ShowPopup
        objCmb.Delete
        Set objCmb = Nothing
    End If
End Sub


in a standard module :

Code:
Sub Copy_from_Clipboard()

    If Application.CutCopyMode Then UserForm1.TextBox1.Paste

End Sub


Regards.
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi Jaafar.

No, your not missing anything. It was a ready-made solution I found on the net and simply edited it a bit. You will, of course, still end up writing a fair amount of code to duplicate the functionality of the previous post.
 
Upvote 0
Whoa!

I dropped in the code you posted and it works perfectly with absolutely no edits!

That was extremely kind of you Right_Click.

Thank you VERY much!!!!!!
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,085
Members
452,378
Latest member
Hoodzy01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top