PC Review


Reply
Thread Tools Rate Thread

Adding a right-click context menu to Excel VBA TextBoxes

 
 
ram gopal
Guest
Posts: n/a
 
      24th Nov 2008
Hello All,

I am created text boxes using
views-->Toolbars---->control toolbox in excel.

I need VBA code for right mouse button to copy, paste,delete and select
all options.

Could some one help me above situation.

Thanks,
Ram


*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Doug Glancy
Guest
Posts: n/a
 
      24th Nov 2008
Ram

Add this code into the code module for the worksheet that contains the
textbox. To do this, right-click the tab of the worksheet with the textbox
and choose "View Code" and then paste the code into the module. Change the
name of the textbox to match yours:

Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
If Button = vbKeyRButton Then
Call MakeMenu
Application.CommandBars("TextBox Bar").ShowPopup
End If
End Sub

Sub MakeMenu()
Dim cbTextBox As CommandBar
Dim cmdTest As CommandBarButton

'in case it already exists
Call DeleteBar
Set cbTextBox = CommandBars.Add(Name:="TextBox Bar", Position:=msoBarPopup,
temporary:=True)
With cbTextBox
Set cmdTest = .Controls.Add(Type:=msoControlButton, temporary:=True)
With cmdTest
.Style = msoButtonIconAndCaption
.FaceId = 3
.Caption = "test"
.OnAction = "TestRoutine"
End With
End With
End Sub

Sub DeleteBar()
'in case it doesn't exist
On Error Resume Next
CommandBars("TextBox Bar").Delete
End Sub

Then in a regular module, add this code. This is the subroutine that's
named in the OnAction property of the button. This is just an example:

Public Sub TestRoutine()
MsgBox "Test Pressed!"
End Sub

hth,

Doug

"ram gopal" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello All,
>
> I am created text boxes using
> views-->Toolbars---->control toolbox in excel.
>
> I need VBA code for right mouse button to copy, paste,delete and select
> all options.
>
> Could some one help me above situation.
>
> Thanks,
> Ram
>
>
> *** Sent via Developersdex http://www.developersdex.com ***



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Context Menu (right click) Options martin.j.jung@googlemail.com Microsoft Excel Discussion 5 4th Sep 2008 07:36 PM
Adding Browser choice to right-click context menu Gordon Windows XP Customization 0 5th Dec 2007 09:24 AM
Adding right click context menu in VB.net Preeti Microsoft VB .NET 1 14th Apr 2007 08:50 AM
Adding right click context menu in VB.net Preeti Microsoft Dot NET 0 14th Apr 2007 05:37 AM
Adding to the right-click context menu. Tim Pulley Microsoft Outlook Program Addins 1 23rd Nov 2004 07:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:17 AM.