Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if specific Menu Item exist in the Mouse Right Click Menu

The following code adds Menu Items to the mouse right click menu successfully.

Sub AddMenuItemsToTheMouseRightClickMenu()
Application.ShortcutMenus(xlWorksheetCell).MenuItems.AddMenu Caption:=("FIRST MENU")
Application.ShortcutMenus(xlWorksheetCell).MenuItems.AddMenu Caption:=("SECOND MENU")
Application.ShortcutMenus(xlWorksheetCell).MenuItems.AddMenu Caption:=("THIRD MENU")
End Sub

I need a vba code which checks if specific Menu Item exists in the mouse right click menu.

So, the following code needs to be repaired.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Sub CheckIfSpecificMenuItemExistInTheMouseRightClickMenu()
    If Application.ShortcutMenus(xlWorksheetCell).MenuItems("SECOND MENU").Count > 0 Then
        MsgBox "Yes, exist"
    End If
End Sub

I did some internet searches but there is no solution.

>Solution :

Instead of using COUNT, try using INDEX instead:

If Application.ShortcutMenus(xlWorksheetCell).MenuItems("SECOND MENU").Index > 0 Then
    MsgBox "Yes, exist"
End If

You will need to add an error handler for when it doesn’t exist, however.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading