我正在处理 Excel 工作簿的左侧菜单。我想要实现的是有一个可以更改菜单背景颜色的设置,范围是所有工作表中的 A1:A200。我可以使用下面的代码执行此操作,并且它运行良好,问题是一个单元格,即活动工作表单元格(与实际工作表名称无关的文本),具有与其他单元格不同的背景颜色。我不知道如何检测该单元格并确保在选择 NewColour 时它具有 AccentColour,我原本想循环遍历所有单元格,但这似乎需要很长时间;
Private Sub ChangeMenuBackgroundColour()
'Procedure to change the background colour of the left hand menu
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim cursheet As Worksheet
Dim NewColour As Long
Dim CurrentColour As String
Set wbBook = ThisWorkbook
Set CurrentSheet = ActiveSheet
CurrentColour = Range("Menu_Background_Colour").Value
Application.ScreenUpdating = False
Select Case CurrentColour
Case "Black"
NewColour = RGB(50, 50, 50)
AccentColour = RGB(75, 85, 95)
Case "Blue"
NewColour = RGB(55, 95, 145)
AccentColour = RGB(80, 130, 190)
Case "Brown"
NewColour = RGB(90, 65, 50)
AccentColour = RGB(115, 100, 95)
Case "Green"
NewColour = RGB(80, 130, 95)
AccentColour = RGB(105, 190, 140)
Case "Grey"
NewColour = RGB(90, 90, 90)
AccentColour = RGB(115, 125, 135)
Case "Orange"
NewColour = RGB(220, 120, 60)
AccentColour = RGB(245, 145, 105)
Case "Purple"
NewColour = RGB(125, 75, 135)
AccentColour = RGB(150, 110, 180)
Case "Red"
NewColour = RGB(180, 65, 65)
AccentColour = RGB(205, 100, 110)
End Select
For Each wsSheet In wbBook.Worksheets
If Not wsSheet.Name = "Blank" Then
wsSheet.Activate
With ActiveSheet
Range("A1:A200").Interior.Color = NewColour
End With
End If
Next wsSheet
CurrentSheet.Select
Application.ScreenUpdating = True
End Sub