Random CMYK Colours - I tried Bard and got this... below script, but this is not working, please someone correct this

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

Parents
No Data
Reply
  • My code in c#, tested


    [CgsAddInMacro]
       public void ApplyRandomCMYK()
       {
           ShapeRange sr = corelApp.ActiveSelectionRange;
           sr.ApplyUniformFill(corelApp.CreateCMYKColor(0000));
           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.Refresh
    End Sub

Children