|
一个特定条件的条件格式的方式
- Public WithEvents app As Excel.Application
- Private Sub app_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
-
- '选中区域变化时变化聚光灯
- If f1 = True And Target.Columns.Count <> Cells.Columns.Count And Target.Rows.Count <> Cells.Rows.Count Then '选中整行 和 整列 时不显示
- On Error Resume Next
-
- focuslamp.Delete '方法2
-
- Set focuslamp = Union(Target.EntireRow, Target.EntireColumn).FormatConditions.Add(Type:=xlExpression, Formula1:="=true=true")
-
- focuslamp.Interior.Color = RGB(204, 255, 204)
-
- End If
-
- End Sub
- Private Sub app_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean)
- Call DelFocuslamp(Wb)
- End Sub
- Private Sub app_WorkbookBeforePrint(ByVal Wb As Workbook, Cancel As Boolean)
- Call DelFocuslamp(Wb)
- End Sub
- Private Sub app_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As Boolean, Cancel As Boolean)
- Call DelFocuslamp(Wb)
- End Sub
- Sub DelFocuslamp(ByVal Wb As Workbook)
- '打印/关闭/保存 时 如果聚光灯位于关闭关键 则需要删除
- On Error Resume Next
- If Not focuslamp Is Nothing Then
- If focuslamp.Parent.Parent.Parent.Name = Wb.Name Then
- focuslamp.Delete '方法2
- Set focuslamp = Nothing
- End If
- End If
-
- 'Wb.Save '如果保存此行 不适宜自动保存
- End Sub
复制代码
在没有删除干净的时候
- Sub 清除聚光灯()
- Dim wb1 As Workbook
- Dim sht As Worksheet
- Set wb1 = ActiveWorkbook
- 聚光灯_关闭
- On Error Resume Next
-
- For Each sht In wb1.Sheets
- Err.Clear
- fcount = 0
- fcount = sht.Cells.FormatConditions.Count
- If fcount > 0 Then
- For Each f In sht.Cells.FormatConditions
- If f.Formula1 = "=TRUE=TRUE" Then
- f.Delete
- End If
- Next
- End If
- Next
-
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|