我在电子表格中插入了一堆矩形。它们被称为:
矩形 1 至矩形 172
是否有一些代码可用于更改填充和线条颜色?我会将代码分配给另一个可以更改颜色的按钮。
答案1
看看这是否能满足你的需要让每个矩形调用这个宏
Sub doRectChange()
Dim c
c = Application.Caller
MsgBox (c)
With ActiveSheet.Shapes(c)
.Fill.ForeColor.SchemeColor = 3
.Fill.Transparency = 0#
.Line.Weight = 3#
.Line.DashStyle = msoLineSolid
.Line.Style = msoLineSingle
.Line.Transparency = 0#
.Line.Visible = msoTrue
.Line.ForeColor.SchemeColor = 6
End With
End Sub
这是另一种选择 当然,您的按钮数量可能会有所不同,因此请进行调整。
Sub allRectanglesColor()
Dim c
Dim color
c = Application.Caller
'MsgBox (c)
Select Case c
Case "Button 1"
color = 10
Case "Button 2"
color = 12
Case "Button 3"
color = 17
End Select
ActiveSheet.Rectangles.Select
With Selection.ShapeRange
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.SchemeColor = color
End With
End Sub