ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding a right-click context menu to Excel VBA TextBoxes (https://www.excelbanter.com/excel-programming/420438-adding-right-click-context-menu-excel-vba-textboxes.html)

ram gopal

Adding a right-click context menu to Excel VBA TextBoxes
 
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 ***

Doug Glancy

Adding a right-click context menu to Excel VBA TextBoxes
 
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" wrote in message
...
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 ***





All times are GMT +1. The time now is 09:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com