View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Add break in macro

I assigned this macro to the shape.

Option Explicit
Sub TestMe()

Dim myShape As Shape
Dim myColorVals As Variant
Dim myColor As Long
Dim res As Variant

Set myShape = ActiveSheet.Shapes(Application.Caller)

myColorVals = Array(11, 13, 10, 51)

myShape.Fill.Visible = True
myShape.Fill.Solid

res = Application.Match(myShape.Fill.ForeColor.SchemeCol or, myColorVals, 0)

If IsError(res) Then
'not one of the specified colors, so use the first
myColor = myColorVals(LBound(myColorVals))
Else
If res UBound(myColorVals) Then
'go back to the start
myColor = myColorVals(LBound(myColorVals))
Else
'go to the next color
myColor = myColorVals(res)
End If
End If

myShape.Fill.ForeColor.SchemeColor = myColor

End Sub

Set myShape = ActiveSheet.Shapes(Application.Caller)
will be the shape that you clicked on

myColorVals = Array(11, 13, 10, 51)
will be an array(0 to 3)

But res (in the application.match() portion)
will return 1,2,3,4
So if the match is on the first color (11) (element 0 in the array), the next
element will be element #1 (same as what res is equal to).




Thomp wrote:

Let me first preface by saying I know very little VBA but what I am
wanting to do is to create a macro that changes an autoshape color
each time I click on the autoshape. The macro I have below just runs
from the first color to the last. I want to click the shape and change
the color on each click. In fact it needs to loop so that every time I
click the shape it moves between the four colors chosen. I guess I am
looking for some kind of macro break

Here is my code thus far.

ActiveSheet.Shapes("AutoShape 67").Select
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 11
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 13
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 10
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 51
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.Solid

thanks in advance
Thomp


--

Dave Peterson