View Single Post
  #1  
Old 02-01-2013, 05:47
nic nic is offline
Member
 
Join Date: May 2009
Posts: 90
Default Swap the colors of shapes

Hi
Im trying to randomly swap the colours of shapes in a document.
The code below is intended to loop through all the shapes and swap colour with a random shape but it fails with "Object variable or with block variable not set" at the line

c = sr(n).Fill.UniformColor '

Any help appreciated.

Thanks
Nic


Code:
Sub swapcolours()

Dim s As Shape
Dim sr As ShapeRange

Dim n As Double    ' loop counter

Dim R As Single    ' random shape
Dim tot As Single  ' total number of shapes

Dim c As Color     ' looping shapes original color
Dim d As Color     ' random shapes original color

Optimization = True
tot = ActivePage.Shapes.Count
Set sr = ActiveLayer.Shapes.All

For n = 1 To tot      ' loop thru all the shapes in order

    R = Int(Rnd(tot)) ' select a random shape

c = sr(n).Fill.UniformColor ' looping shapes color
d = sr(R).Fill.UniformColor ' random shapes color

sr(n).Fill.ApplyUniformFill d
sr(R).Fill.ApplyUniformFill c

Next n

Optimization = False
End Sub
Reply With Quote