1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| Sub Change_Picture_Location()
'Error Handler
On Error GoTo ErrH:
'Declaration of Variables
Dim flag As Boolean
Dim myShape As Shape
Dim cTop As Double
Dim cLeft As Double
Dim cHeight As Double
Dim cWidth As Double
' +-+- Check whether Selection is Shape or Range -+-+
flag = False
For Each myShape In ActiveSheet.Shapes
If myShape.Name = Selection.Name Then
flag = True
Exit For
Else
flag = False
End If
Next
ErrH:
On Error GoTo endH
' +-+- Checking Over -+-+
If flag = True Then
'Saving Selected Image Attributes
cTop = Selection.ShapeRange.Top
cLeft = Selection.ShapeRange.Left
cHeight = Selection.ShapeRange.Height
cWidth = Selection.ShapeRange.Width
'Delete Selected Image
Selection.Delete
'Insert New Image
ActiveSheet.Pictures.Insert(Application.GetOpenFilename).Select
'Applying Old attributes to the New image
Selection.ShapeRange.Top = cTop
Selection.ShapeRange.Left = cLeft
Selection.ShapeRange.Height = cHeight
Selection.ShapeRange.Width = cWidth
Else
MsgBox "Please select a picture not the range."
End If
endH:
End Sub |
Partager