Add item to right click menu?

davez

Board Regular
Joined
Feb 12, 2003
Messages
144
Office Version
  1. 365
Platform
  1. Windows
Hi all, I use Excel 365 & often have to paste large amounts of data from an external source as text, which involves an extra couple of clicks through the right click menu - paste special/text/ok. So to save myself some time I am wondering if theres is a way to add the paste text option to the right click menu?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Altering context menus is tricky. Can you not use a macro to perform the steps?
 
Upvote 0
It is actually fairly easy to add an entry to the right-click context menu in Excel.

example of code to copy/paste into the 'ThisWorkbook' module of a workbook:
VBA Code:
Option Explicit

Private Sub Workbook_Open()
'
    Dim cmdBtn  As CommandBarButton
'
    Set cmdBtn = Application.CommandBars("Cell").Controls.Add(Temporary:=True, Before:=1, Type:=msoControlButton)   ' Add a custom button option to the right-click context menu.
'
    With cmdBtn
        .Caption = "Paste Special Text"                                                                             '   Caption for the added right click menu button
        .FaceId = 755                                                                                               '   Icon to display for the added right click menu button
        .OnAction = "PasteSpecialText"                                                                              '   Name of the code module that you want to run when the added right click option is selected
    End With
End Sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)
'
    Application.CommandBars("Cell").Controls("Paste Special Text").Delete                                           ' Delete the custom right click button when the workbook is closed.
End Sub

That /\ /\ /\ code will add the 'Paste Special Text' option to the top of the right click menu


And then in a regular module, an example of the code that you want to run when the added right click option is selected:
VBA Code:
Sub PasteSpecialText()
'
    ActiveSheet.PasteSpecial Format:="Text"
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,215,091
Messages
6,123,062
Members
449,090
Latest member
fragment

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