Option Explicit
Private WithEvents cmbrs As CommandBars
Private lTotalShapes As Long
Private oPrevSheet As Worksheet
Private Sub Workbook_Activate()
Call TagShapes
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Call TagShapes
End Sub
Private Sub TagShapes()
Dim oShp As Shape, oGrpShape As Shape
On Error Resume Next
For Each oShp In ActiveSheet.Shapes
oShp.AlternativeText = CStr(oShp.Left) & "*" & CStr(oShp.Top) & "*" & CStr(oShp.Width) & "*" & CStr(oShp.Height)
lTotalShapes = lTotalShapes + 1
Next
Set oPrevSheet = ActiveSheet
Set cmbrs = Application.CommandBars
End Sub
Private Sub cmbrs_OnUpdate()
Dim sTagsArray() As String
Dim oShp As Shape, oGrpShape As Shape
Dim bCancel As Boolean
If oPrevSheet.Name <> ActiveSheet.Name Or ActiveSheet.Shapes.Count <> lTotalShapes Then lTotalShapes = 0: Call TagShapes: Exit Sub
If TypeName(Selection) = "Range" Or TypeName(Selection) = "Nothing" Then Exit Sub
For Each oShp In ActiveSheet.Shapes
With oShp
sTagsArray = Split(.AlternativeText, "*")
If sTagsArray(0) <> CStr(.Left) Or sTagsArray(1) <> CStr(.Top) Or _
sTagsArray(2) <> CStr(.Width) Or sTagsArray(3) <> CStr(.Height) Then
Call Shapes_AfterMoveOrResize(oShp, .Left, .Top, .Width, .Height, bCancel)
If bCancel Then Application.Undo
Call TagShapes
Exit Sub
End If
End With
Next
Set oPrevSheet = ActiveSheet
End Sub
[B][COLOR=#008000]'==================================================================[/COLOR][/B]
[B][COLOR=#008000]'Pseudo-event routine that fires when any shape is moved or resized[/COLOR][/B]
[B][COLOR=#008000]' - Set the Cancel argument to TRUE to undo the moving or resizing[/COLOR][/B]
[B][COLOR=#008000]'==================================================================[/COLOR][/B]
Private Sub Shapes_AfterMoveOrResize _
( _
ByVal Shp As Shape, _
ByVal x As Single, _
ByVal y As Single, _
ByVal cx As Single, _
ByVal cy As Single, _
ByRef Cancel As Boolean _
)
Dim sMsg As String
[B][COLOR=#008000] 'Cancel = True <=== Set this arg to TRUE to undo the operation !!![/COLOR][/B]
sMsg = Space(20) & vbNewLine & vbNewLine
sMsg = sMsg & "You have altered the size or the position" & vbNewLine & "of the shape : " & _
"( " & Shp.Name & " )" & vbNewLine & vbNewLine
sMsg = sMsg & " - New LEFT Value := (" & x & " pt" & ")" & vbNewLine & vbNewLine
sMsg = sMsg & " - New TOP Value := (" & y & " pt" & ")" & vbNewLine & vbNewLine
sMsg = sMsg & " - New WIDTH Value := (" & cx & " pt" & ")" & vbNewLine & vbNewLine
sMsg = sMsg & " - New HEIGHT Value := (" & cy & " pt" & ")" & vbNewLine & vbNewLine
sMsg = sMsg & " - Cancel Move\Resize Opeartion : (" & IIf(Cancel, "Yes", "No") & ")"
MsgBox sMsg, vbInformation, "Shape Move\Resize Pseudo-Event."
End Sub