VBA Change event when selecting a shape

Formula11

Active Member
Joined
Mar 1, 2005
Messages
468
Office Version
  1. 365
Platform
  1. Windows
Is there a change event in VBA each time a different shape is selected?

The change event would be while a useform is active.

The shapes are Oval and Rectangle.
Each time I select a shape, the useform would display the Height and Width.

The change event is what I was looking for, it's possible that is.
 
No, a shape has no click event,
Just my uneducated opinion I guess, but I'd say we're dealing in semantics here, or you are mistaken. Probably the former. This is what the 'assign macro' dialog opened up for the (non) event for a star placed on the sheet from the ribbon:

Sub Star5Points2_Click()

End Sub

The fact that the code fires when you click on the shape is bewildering if the shape has no click event.
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
What is it you're trying to accomplish?
Shapes are inserted via a userform to begin with.
Later on, I want to edit the shape using fields in the userform (height, width, line thickness, etc).

So clicking on a shape would be like an event which would bring up the form, and show existing parameters (height, width, etc).
 
Upvote 0
Just my uneducated opinion I guess, but I'd say we're dealing in semantics here, or you are mistaken. Probably the former. This is what the 'assign macro' dialog opened up for the (non) event for a star placed on the sheet from the ribbon:

Sub Star5Points2_Click()

End Sub

The fact that the code fires when you click on the shape is bewildering if the shape has no click event.
Strictrly speaking, that's not a click event (with code in a worksheet, workbook, or class module), it's an assigned macro in a regular code module. But the effect is the same, except that EnableEvents has no effect on whether the assigned macro runs when the shape is clicked.
 
Upvote 0
Shapes are inserted via a userform to begin with.
Later on, I want to edit the shape using fields in the userform (height, width, line thickness, etc).

So clicking on a shape would be like an event which would bring up the form, and show existing parameters (height, width, etc).
Interesting. I envision a different, perhaps more complicated approach, but which would not rely on procedures assigned to the shapes. The UserForm would have a listbox showing all shapes on the active sheet. When the form is first launched, you could have it pop up with any selected shapes highlighted in the listbox. Selecting a shape from the listbox would select the shape in the sheet, and would display its dimensions in textboxes. Changing these dimensions would resize the shape. Using a muilti-select listbox would allow you to adjust the size of all selected shapes at once. You could have a button to unselect all shapes, and another to refresh the list.
 
Upvote 0
EnableEvents has no effect on whether the assigned macro runs when the shape is clicked.
Thanks for that info. The part that bothers me about the whole thing is that it is the very clicking on the shape that runs the code. This may be a case where something in vba or an application model isn't exposed or may not even be documented. I have seen this before. From M$:
An event is a signal that informs an application that something important has occurred. For example, when a user clicks a control on a form, the form can raise a Click event and call a procedure that handles the event.
Clicking on the shape and the _Click assigned to the procedure name seems to satisfy all the requirements for declaring that as being an event, even if it's not in the application model documentation. I'll leave it at that and let you focus on helping the OP. Regards.
 
Upvote 0
Interesting. I envision a different, perhaps more complicated approach, but which would not rely on procedures assigned to the shapes. The UserForm would have a listbox showing all shapes on the active sheet. When the form is first launched, you could have it pop up with any selected shapes highlighted in the listbox. Selecting a shape from the listbox would select the shape in the sheet, and would display its dimensions in textboxes. Changing these dimensions would resize the shape. Using a muilti-select listbox would allow you to adjust the size of all selected shapes at once. You could have a button to unselect all shapes, and another to refresh the list.

Would this refresh the next time a shape is selected?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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