Launch a macro when a shape is moved

LSA_1984

New Member
Joined
Aug 11, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello,
Here my challenge:

I've placed 4 rectangles - one below each other (with a little bit of space inbetween). I've named them R1, R2, R3 and R4. There current position is
(...).Left = 60 (for all)
(...).Top = 60 (for R1), 80 (for R1), 100 (for R1) & 120 (for R1)

My goal is to be capable to re-order them by moving the shapes: if I click with my mouse on "R4" and move it up somewhere inbetween "R1" and "R2", I want (after releasing my mouse) to see "R1" staying at its first position, "R4" beeing at the second position (coordinates: .Left = 60 and .Top = 80), "R2" moving down to the 3rd position and "R3" moving down to the last position. New order beeing R1-R4-R2-R3.

My approach so far is to have two table: One providing the .Left and .Top coordinates for the 4 expected positions (reference table) and the other one gathering the .Left and .Top positions of the 4 rectangles. I can anytime (upon demand) check the real position of the 4 rectangles and decide, based on their real position, in which order I want to see them appearing in their respective positions. So if I move "R4" manually inbetween "R1" and "R2", my "real position table" will show that the .Top value for "R4" is now the second lowest => I can reorder the 4 rectangles as expected: "R1", "R4", "R2", "R3"

My problem: today i need to click on a buton to update the "real position table". I want the macro to start as soon as a position move has been detected.

Any suggestions? best practises?

Thank you

Laurent
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

bobsan42

Well-known Member
Joined
Jul 14, 2010
Messages
1,855
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
the are several posts in this message board on this subject - Events for Shapes or something similar.
It is not naturally supported by VBA.

However check this link: Shape events in VBA
I have not yet tested it myself but it looks promissing.
 

LSA_1984

New Member
Joined
Aug 11, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
the are several posts in this message board on this subject - Events for Shapes or something similar.
It is not naturally supported by VBA.

However check this link: Shape events in VBA
I have not yet tested it myself but it looks promissing.
Thanks - I will have a look!
 

Forum statistics

Threads
1,148,007
Messages
5,744,319
Members
423,861
Latest member
Ka3EeM

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
Top