Return caption of right click selection

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,645
Office Version
  1. 365
Platform
  1. Windows
I am adding a custom menu to the options when a right click is performed using the following
Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)

Dim objMenu As Object

Dim rngSource As Range

Dim strSource As String

Dim intCount As Integer

If Not Application.Intersect(Target, Range("E9:E508")) Is Nothing Then
   Else
   Exit Sub
End If

For Each objMenu In Application.ShortcutMenus(xlWorksheetCell).MenuItems
   If objMenu.Caption = "SOURCES" Then
      objMenu.Delete
      Else
   End If
Next objMenu

If ActiveCell.Offset(0, -4) = False Then
   Exit Sub
   Else
End If

Set objMenu = Application.ShortcutMenus(xlWorksheetCell).MenuItems.AddMenu("SOURCES", 1)

With objMenu.MenuItems
   Set rngSource = Sheets("File Data").Range("FD_SourceStart")
   
   intCount = 1
   
   Do Until rngSource = ""
      strSource = rngSource
      
      .Add strSource, "AddSource", intCount
      
      intCount = intCount + 1
      
      Set rngSource = rngSource.Offset(1, 0)
   Loop
End With

Set rngSource = Nothing

Set objMenu = Nothing

End Sub
When the right click menu is shown to the user and the make a selection from the SOURCES menu, I need to return the caption of the selection made as this needs adding to the activecell.


TIA
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Found it after a bit more digging!
Code:
ActiveCell = Application.CommandBars.ActionControl.Caption
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,212
Members
453,023
Latest member
alabaz

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