I want this macro to run after every 3 seconds so that each time i move a selected shape among many shapes its color should change.
But this code only works once... It doesn't repeat or doesn't change the color of next shape i select and move to particular position.
Sub UpdateColor()
Dim ActiveShape As Shape
Dim UserSelection As Variant
Dim d As Integer
Set UserSelection = ActiveWindow.Selection
On Error GoTo NoShapeSelected
Set ActiveShape = ActiveSheet.Shapes(UserSelection.Name)
On Error Resume Next
With ActiveShape
d = ActiveShape.Left
If d >= 0 And d <= 123.5 Then
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 128, 0)
ElseIf d >= 124 And d <= 336.75 Then
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(0, 102, 204)
ElseIf d >= 336.76 And d <= 547.5 Then
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(0, 153, 0)
ElseIf d >= 547.51 And d <= 776.25 Then
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(219, 38, 10)
ElseIf d >= 776.25 Then
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(211, 211, 211)
End If
End With
Exit Sub
NoShapeSelected:
MsgBox "You do not have a shape selected!"
Application.OnTime Now + TimeValue("00:00:03"), "GetPosition3"
End Sub
Please tell me what is wrong with the code.
But this code only works once... It doesn't repeat or doesn't change the color of next shape i select and move to particular position.
Sub UpdateColor()
Dim ActiveShape As Shape
Dim UserSelection As Variant
Dim d As Integer
Set UserSelection = ActiveWindow.Selection
On Error GoTo NoShapeSelected
Set ActiveShape = ActiveSheet.Shapes(UserSelection.Name)
On Error Resume Next
With ActiveShape
d = ActiveShape.Left
If d >= 0 And d <= 123.5 Then
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 128, 0)
ElseIf d >= 124 And d <= 336.75 Then
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(0, 102, 204)
ElseIf d >= 336.76 And d <= 547.5 Then
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(0, 153, 0)
ElseIf d >= 547.51 And d <= 776.25 Then
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(219, 38, 10)
ElseIf d >= 776.25 Then
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(211, 211, 211)
End If
End With
Exit Sub
NoShapeSelected:
MsgBox "You do not have a shape selected!"
Application.OnTime Now + TimeValue("00:00:03"), "GetPosition3"
End Sub
Please tell me what is wrong with the code.