useing a macro to move a drawing object in excel

stafire_18

Board Regular
Joined
Dec 8, 2004
Messages
162
is there anyway i can create a macro to move a drawing object like an inserted line back to a default location if it is ever moved?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi,

I can see the drawing object name in Name box when I click on the object. It is "Line 1" in my example.
I would first validate if it was moved by checking Left and Top properties of the shape object then replace it if necessary like below:

Code:
  With Sheet1.Shapes("Line 1")
    If .Left <> 10 Or .Top <> 10 Then
      .Left = 10
      .Top = 10
    End If
  End With


I hope it helps.
 
Upvote 0
Same. You will only use the groupped object name instead "Line 1".
Similarly I created another line, which is called as "Line 2" and groupped these 2 lines and when I click on this groupped object, I can see its name is "Group 3" for example. And used following code instead:

Code:
  With Sheet1.Shapes("Group 3") 
    If .Left <> 10 Or .Top <> 10 Then 
      .Left = 10 
      .Top = 10 
    End If 
  End With

Changed only object name in Shapes collection.

Suat
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,177
Members
448,554
Latest member
Gleisner2

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