Return caption of right click selection

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,600
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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Found it after a bit more digging!
Code:
ActiveCell = Application.CommandBars.ActionControl.Caption
 
Upvote 0

Forum statistics

Threads
1,215,366
Messages
6,124,516
Members
449,168
Latest member
CheerfulWalker

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