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