以下代码在Excel 2013上运行良好。但在Excel 2007上,我遇到了问题。
Function IsMasked() As Boolean
Dim wksTables As Worksheet
Set wksTables = GetSheetByCodename(ThisWorkbook, "wTables")
Dim loMask As ListObject
Set loMask = wksTables.ListObjects("tMask")
Dim lor As ListRow
For Each lor In loMask.ListRows
Dim sWorksheetName As String
Dim sRangeAddress As String
Dim sCompleteAddress As String
sWorksheetName = Intersect(lor.Range, loMask.ListColumns("Worksheet").DataBodyRange)
sRangeAddress = Intersect(lor.Range, loMask.ListColumns("Range").DataBodyRange)
Dim R As Range
Set R = ThisWorkbook.Worksheets(sWorksheetName).Range(sRangeAddress)
With R
Dim bMasked As Boolean
Dim fc As Object
For Each fc In .FormatConditions
If TypeName(fc) = "FormatCondition" Then
If fc.Interior.Color = RGB(0, 0, 0) And fc.Font.Color = RGB(0, 0, 0) Then
'Range has mask if any formatcondition is mask
bMasked = True
Exit For
End If
End If
Next fc
If bMasked = False Then
'Mask is false if any specified range does not have mask
Exit For
End If
End With
Next lor
IsMasked = bMasked
End Function
即使内部颜色设置为空并且字体颜色为红色, If fc.Interior.Color = RGB(0, 0, 0) And fc.Font.Color = RGB(0, 0, 0)
的计算结果为true。
当我在本地窗口中查看fc
时,很多属性都会说application-defined
或object-defined error
。我不知道这是否有任何线索。