I would like to programmatically display the right click context menu with focus through a VBA macro in Word 2007.
This would allow me to map the macro to a hotkey and expose the menu with focus without leaving the keyboard. I assumed this would be done through the Application
object's CommandBars
collection, accessed along the lines of :
Application.CommandBars.'access appropriate mehod or member here'
But I do not see any method or member that seems like it would show the context menu. Is it possible to achieve this through a VBA macro?
EDIT:
As suggested I looped through each CommandBar and obtained the name and index to try and find out which CommandBar index to use:
Sub C_RightClick()
'Activates right-click context menu
'
Dim cbar As Office.CommandBar
Dim cbarIndex As Integer
Dim testString As String
Dim cBarsArray(0 To 500)
Dim arrayCounter As Integer
testString = ""
arrayCounter = 1
For Each cbar In CommandBars
'TRUE if right-click
'If LCase(cbar.Name) = 'right-click' Then
' cbarIndex = cbar.Index
'End If
testString = testString + CStr(cbar.Index) + " " + cbar.Name + " " + CStr(cbar.Type = msoBarTypePopup) + vbCrLf
Debug.Print cbar.Name; " "; cbar.Type = msoBarTypePopup
'Add name to array and increment counter
cBarsArray(arrayCounter) = cbar.Name
arrayCounter = arrayCounter + 1
Next cbar
MsgBox testString
'Application.CommandBars(cbarIndex).ShowPopup
End Sub
However, I do not see any titled 'Right-Click'. I thought it may be 'Standard' , whose index is 1, but received an error when I attempted to access it.
If anyone knows the correct name for the default right-click context menu that appears in Word 2007 when the Home
tab is selected, it would be appreciated. Otherwise, I will take that question to SuperUser and research on my own. Thank you for the help.