4

Is there a way to disable the right click menu for shapes like e.g. rectangles in VBA?

I tried:

Private Sub Workbook_Open()
'    Application.WindowState = xlMaximized
    Application.DisplayFullScreen = True
    Application.CommandBars("Ply").Enabled = False
    Application.CommandBars("Shapes").Enabled = False
End Sub

but this does not seem to work.

L42
  • 19,427
  • 11
  • 44
  • 68
woipi
  • 43
  • 9

2 Answers2

2

The right-click menu (aka, context menu) is not a Command Bar.

You may know Command Bars by their older name, Toolbars, or their newer name, Ribbons.

Although you can capture and/or disable a right-click event on a worksheet, this doesn't apply to objects like shapes.

However, you can prevent the context menu from showing by protecting the worksheet from changes (with or without a password).

If necessary you can allow some changes, but not others, to be made by the user. More information at this link.

enter image description here

ashleedawg
  • 20,365
  • 9
  • 72
  • 105
  • thank you for your reply - the problem however is that on the other hand i need to be able to select the shapes and also to generate them per vba.. when i protect the sheet neither is possible anymore.. – woipi Dec 27 '17 at 11:30
  • When you need to creaye or manipulate the shapes via VBA, you can programmatically unprotect & reprotect the sheet as required. Why do the users need to be able to select the shapes? There's likely an alternative. – ashleedawg Dec 27 '17 at 16:13
  • hm yeah you are right that should not be a problem with the creation of new shapes - but the selection of shapes is crucial to my program as i need to select various shapes to align them via vba.. basically i overwrite the left, or top values of the selected shapes with the value of the first selected shape.. – woipi Dec 27 '17 at 16:27
  • Are there a limited number of shapes? If so, perhaps an alternate method of selecrion would work, like [static or dynamic] checkboxes...? A screen shot example of what you're doing might be helpful. – ashleedawg Dec 27 '17 at 16:32
  • 1
    ....since unfortunately there's no built-in functionality for disabling only certain interactions with shapes. (Short of creating a custom add-on with C#) – ashleedawg Dec 27 '17 at 16:34
0

I have attached some screenshots of my application just to describe what I want to archive.

The problem is that the menu is realy annoying when trying to select more than one shape.

enter image description here

enter image description here

woipi
  • 43
  • 9
  • It is possible, but very very annoying with Excel :) , as you noticed. Not sure, if Excel is the best program therefore at all. MS Visio could be better suited. – Hristo Feb 22 '23 at 07:05