将 Excel 工作表标签的颜色复制到单元格



我在一个 excel 文件中有几百个工作表,其中一个工作表引用了所有其他工作表(跟踪表(。其他工作表具有基于完成的颜色编码选项卡,我想在跟踪器表中引用它。有没有办法找到工作表选项卡的颜色,并将其添加到跟踪器表中相应的跟踪器行中?

我创建了一个示例工作表来尝试复制您的问题。有一个"跟踪表",以及其他几个带有彩色标签的空白工作表。我不知道您对工作表的命名约定是什么,所以我只使用了"工作表";我还使用了一个按钮来执行以下代码,但您可以在使用时使用它:

Sub Button2_Click()
Dim tabColorIndex As Variant, index As Integer
'For all of your sheets being tracked
For index = 1 To 3
'Retrieve the tab's colorIndex at index
tabColorIndex = Sheets("Sheet" & index).Tab.colorIndex
'Set the cells' colors in the respective row from columns A to F
Sheets("TrackerSheet").Range("A" & index & ":F" & index).Interior.colorIndex = tabColorIndex
Next index
End Sub

这将为行着色,如上面的链接所示。

Dim ws As Worksheet
Set ws = ActiveWorkbook.Worksheets("Sheet1")
MsgBox ws.Tab.Color

这将返回颜色的值为十六进制/RGB,具体取决于它是否是主要的

这是在消息框中显示以进行测试

实际上做起来很简单的事情,

ActiveWorkbook.Sheets("SheetABC").Tab.Color '<= parse the color of the tab

然后,您可以使用 variablE 根据需要操纵此颜色。

是的,您可以使用:

dim ws as worksheet
ws.tab.color=' numerical value of the tab color you are looking for 

在 if 语句中设置它,并使用计数器跟踪设置颜色的选项卡。您也可以遍历工作簿中的所有工作表:

for each sht in application.worksheet
next sht

最新更新