Vba 将Excel工作表选项卡的颜色复制到单元格

Vba 将Excel工作表选项卡的颜色复制到单元格,vba,excel,excel-formula,Vba,Excel,Excel Formula,我在excel文件中有几百个工作表,其中一个工作表引用了所有其他工作表(跟踪表)。其他工作表有基于完成情况的颜色编码选项卡,我想在跟踪表中引用它。有没有办法找到工作表选项卡的颜色,并将其添加到跟踪表中相应的跟踪行中?实际上做起来很简单 ActiveWorkbook.Sheets("SheetABC").Tab.Color '<= parse the color of the tab ActiveWorkbook.Sheets(“SheetABC”).Tab.Color' 这将返回十六

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

实际上做起来很简单

  ActiveWorkbook.Sheets("SheetABC").Tab.Color '<= parse the color of the tab
ActiveWorkbook.Sheets(“SheetABC”).Tab.Color'
这将返回十六进制/RGB颜色值,具体取决于颜色是否为主颜色

这将显示在msgbox中进行测试

是的,您可以使用:

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
我创建了一个模型来尝试复制您的问题。有一个“TrackerSheet”和其他几个带有彩色标签的空白工作表。我不知道你的命名规则是什么,所以我只使用了“sheets”;我还使用了一个按钮来执行以下代码,但您可以在正在使用的事件中使用它:

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

这将按上面的链接显示行的颜色。

您应该首先显示您的工作
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