前言:我在做完这个问题的时候想出了答案。我没有在任何地方看到这个问题,所以我还是会发布它。
我有一个名为 Table Style 1 的表格样式。 如果日期满足某些条件,我会使用一些 VBA 来格式化单元格:
'formatting for due dates
Select Case (DueDate.Value)
Case ""
DueDate.Value = "No Due Date"
DueDate.Font.ColorIndex = 45
Case Is > Date + 30
With DueDate
.Interior.ColorIndex = 36
.Font.ColorIndex = 53
End With
Case Else
With DueDate
.Interior.ColorIndex = 0
.Font.ColorIndex = 1
End With
End Select
问题出在 else 情况下,Font.ColorIndex。如果字体颜色已被此子程序的先前运行更改,我需要将其重置为表格格式中设置的字体颜色。
我试过颜色索引 0 和 1. 0,因为它适用于 internal.colorindex。1,因为表中未更改单元格的索引。两者都只是将字体颜色更改为黑色。
我有两种可能的方法来做到这一点,但它们可能会失败:
我认为我正在寻找的财产是这样的:
With DueDate
.Interior.ColorIndex = 0
.Font.ColorIndex = myTable.tablestyle.FirstRowStripe.font.colorindex
end with
花了一些时间挖掘,但我找到了我需要的财产。
With DueDate
.Interior.ColorIndex = 0
.Font.ColorIndex = myTable.TableStyle.TableStyleElements(5).Font.ColorIndex
End With
这是有关 TableStyleElements 对象的更多信息。这是XlTableStyleElementType 枚举列表。
我使用了枚举#5,xlRowStripe1。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句