6.9-其它

问题状态变更以后,如从已解决到未解决,或者反之,需要及时更新数据库表示颜色的信息。这里增加了一个工作簿关闭前事件,遍历数据库,根据问题状态更新对应颜色信息。

代码如下

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.DisplayAlerts = False
    
    Call changeTheColor
End Sub
Sub changeTheColor()
    Set sht = ThisWorkbook.Worksheets("问题管理")
    ' 获取行数
    maxRow = sht.Cells(Rows.Count, "Q").End(xlUp).Row
    
    For i = 3 To maxRow Step 1
        problemStatus = sht.Cells(i, "L").Value
        If problemStatus = "已解决" Then
            fillColor = 5287936
            lineColor = 5287936
        Else
            fillColor = 255
            lineColor = 255
            
        End If
        
        sht.Cells(i, "V").Value = fillColor
        sht.Cells(i, "W").Value = lineColor
               
    Next i
    
    Call showAllProblem
End Sub