A few years ago, at my previous employer, I built a VBA macro that had a Right Click Copy/Paste menu for text boxes. Unfortunately, as the code was developed on the company's dime, it had to remain behind when I was downsized.
So far, my current searches are proving uneventful. Does anyone have any examples they are willing to share?
BTW, I was able to create a doubleclick copy to clipboard, but right clicking is far more commonplace and intuitive.
Here is that code:
Private Sub TxtBxNorthing_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Set odata = New DataObject odata.Clear odata.SetText Me.TxtBxNorthing.Text odata.PutInClipboardEnd Sub
TIA
Try using the MouseDown event. A Button value of 2 equates to the right click.
Private Sub TxtBxNorthing_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If Button = 2 Then Set odata = New DataObject odata.Clear odata.SetText Me.TxtBxNorthing.Text odata.PutInClipboard End IfEnd Sub
Rod WingSenior Systems Analyst
FWIW. This topic would probably receive more authoritative input from Microsoft programming forums. From my quick look I would suggest reviewing the Microsoft VBIDE and a respective Microsoft Office object model; and implement similar code as found in this Microsoft post: Adding and Displaying Shortcut Menus
HTH,Bob
Unknown said: I would suggest reviewing the Microsoft VBIDE and a respective Microsoft Office object model
The problem for us is that the Microsoft Office implementation of VBA includes a CommandBars object. It's the absence of that object in MicroStation VBA that makes it hard to add a menu. I'd be happy to be shown to be wrong 8-)
Regards, Jon Summers LA Solutions
From what I can recall of my earlier effort, The popup menu was pretty crude and did not function 100% like a true right click menu, but resembled one enough that users could follow its intent.
I'm thinking, it might have even been a hidden, raised listbox that I made visible at the cursor position, if that's possible. This was over 5 years ago so it's s pretty distant memory.
Charles (Chuck) Rheault CADD Manager
MDOT State Highway Administration
I cannot be sure this is how I did it, as much of what I just tried is not familiar at all. But it appears to be a possibility.
Created a List Box on my user form using these properties - Key items: BackColor (menu color), Special Effect - Raised, Visible = False, Column width (smaller than text placed in it - prevents scroll bars).
With userForm code along these lines:
Private Sub UserForm_Initialize() Me.ListBox1.AddItem ("Copy") Me.ListBox1.AddItem ("Paste")End Sub
Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If Button = 2 Then Me.ListBox1.ListIndex = -1 Me.ListBox1.Top = Y - (Me.ListBox1.Height / 2) Me.ListBox1.Left = X - (Me.ListBox1.Width / 2) Me.ListBox1.Visible = True Me.ListBox1.Font.Size = 10 ElseIf Button = 1 Then Me.ListBox1.Visible = False End IfEnd Sub
Private Sub ListBox1_Click() If Me.ListBox1.ListIndex = 0 Then Debug.Print "Copy to Clipboard" If Me.ListBox1.ListIndex = 1 Then Debug.Print "Paste from Clipboard" Me.ListBox1.Visible = FalseEnd Sub
As you can see, this version only writes to the immediate window - but if that works, my copy to clibboard code will work.
Initially, I placed the .Top and .Left of the list box at Y and X. But I decided to center the list box on the mouse to keep mouse clicks too near an edge from looking too strange - as the listbox does not really float over the form like a commandbar.
I made an example about "pop-up menu on userform "
For View : netmerkez.wordpress.com/.../creating-pop-up-menu-on-userform
You can Download Template Here
That screenshot looks like Excel. As I wrote already, an Office VBA macro that uses the CommandBars object won't work with MicroStation VBA. MicroStation VBA does not provide a CommandBars object.