PHP Code:
Sub Change1()
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = IIf(IsRun, 2, 0)
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = IIf(IsRun, 2, 0)
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = IIf(IsRun, 0, 2)
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = IIf(IsRun, 0, 2)
End With
End Sub
Bây giờ dựa vào sự kiện SelectionChange của sheet, ta làm cho ô D5 thay đổi border như sau:
PHP Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$D$5" Then
If Target = "Run" Then
Target = "Stop"
IsRun = False
Else
Target = "Run"
IsRun = True
End If
Change1
Cells(1, 1).Select
End If
End Sub
Các bạn xem file đính kèm. Thí dụ này chỉ là minh hoạ, không có đoạn code nào được thực thi, nhưng ô D5 đã trở thành 1 nút nhấn thực sự.