Sub ApplyRandomCMYKColors()
Dim s As Shape Dim color As CMYKColor
For Each s In ActiveSelectionRange ' Generate random CMYK values within a specified range Set color = New CMYKColor color.Cyan = Rnd() * 100 color.Magenta = Rnd() * 100 color.Yellow = Rnd() * 100 color.Black = Rnd() * 100
' Apply the random color to the selected object's fill s.Fill.UniformColor = color Next s
End Sub
My code in c#, tested
[CgsAddInMacro] public void ApplyRandomCMYK() { ShapeRange sr = corelApp.ActiveSelectionRange; sr.ApplyUniformFill(corelApp.CreateCMYKColor(0, 0, 0, 0)); Random rd = new Random(); corelApp.Optimization = true; for (int i = 1; i <= sr.Count; i++) { sr[i].Fill.UniformColor.CMYKCyan = rd.Next(100); sr[i].Fill.UniformColor.CMYKMagenta = rd.Next(100); sr[i].Fill.UniformColor.CMYKYellow = rd.Next(100); sr[i].Fill.UniformColor.CMYKBlack = rd.Next(100); } corelApp.Optimization = false; corelApp.Refresh(); }
Converted to VBA by ChatGPT, not tested
Sub ApplyRandomCMYK() Dim sr As ShapeRange Set sr = ActiveSelectionRange
sr.ApplyUniformFill CreateCMYKColor(0, 0, 0, 0) Dim rd As Object Set rd = CreateObject("Scripting.Dictionary")
' Seed the random number generator rd.Add "seed", GetTickCount Randomize rd("seed")
Application.Optimization = True Dim i As Integer For i = 1 To sr.Count sr(i).Fill.UniformColor.CMYKCyan = Int((100 * Rnd) + 1) sr(i).Fill.UniformColor.CMYKMagenta = Int((100 * Rnd) + 1) sr(i).Fill.UniformColor.CMYKYellow = Int((100 * Rnd) + 1) sr(i).Fill.UniformColor.CMYKBlack = Int((100 * Rnd) + 1) Next i Application.Optimization = False Application.RefreshEnd Sub
Wow, Working brother. So nice of you
Brother, i tried this as well for Outline Random Colour. please update this macro.... for random outline colour
Sub RandomizeOutlineColors() Dim s As shape Dim c As Color Dim randomC As Integer, randomM As Integer, randomY As Integer, randomK As Integer Dim selectedShapes As shapes
' Get the selected shapes Set selectedShapes = activeSelection.shapes ' Loop through each selected shape For Each s In selectedShapes ' Generate random CMYK values (0-100) randomC = Int((100 - 0 + 1) * Rnd + 0) randomM = Int((100 - 0 + 1) * Rnd + 0) randomY = Int((100 - 0 + 1) * Rnd + 0) randomK = Int((100 - 0 + 1) * Rnd + 0) ' Create a new CMYK color Set c = s.Line.ForeColor.CMYK s.Line.ForeColor.CMYK = CMYK End With Next sEnd Sub
You can get random colors in the outlines by replacing Fill.UniformColor to Outline.Color