Sub RandomizeColors() Dim shape As Shape Dim red As Integer Dim green As Integer Dim blue As Integer

Randomize ' Initialize random number generator

For Each shape In ActiveSheet.Shapes ' Loop through all shapes on active sheet
    red = Int(Rnd() * 256) ' Generate random value for red component of RGB color
    green = Int(Rnd() * 256) ' Generate random value for green component of RGB color
    blue = Int(Rnd() * 256) ' Generate random value for blue component of RGB color
    
    shape.Fill.ForeColor.RGB = RGB(red, green, blue) ' Set fill color of shape to random RGB color
Next shape

End Sub

' This code randomly changes the fill color of all shapes on the active sheet to a new RGB color every time it is run

生成一段可以运行的有意思的vba代码

原文地址: https://www.cveoy.top/t/topic/cZur 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录