返回列表 上一主題 發帖

[發問] excel 按鈕作動 顏色變化 的問題

[發問] excel 按鈕作動 顏色變化 的問題

啟動 緊急  停止 三個按鈕  如何設定 啟動按鈕有按是綠色 沒有按是灰色
緊急按鈕 和停止按紐  有按是紅色  沒有按是灰色


Option Explicit
Dim TimerEnable As Boolean
Dim TimerStop As Boolean
Dim iValue As Integer


' 啟動
Private Sub CommandButton5_Click()
    TimerEnable = True
    iValue = 0
    WaitFor 1 '每秒計數一次
End Sub


' 緊急
Private Sub CommandButton1_Click()
TimerEnable = False
End Sub


' 停止
Private Sub CommandButton2_Click()
    TimerStop = True
End Sub

Public Sub WaitFor(Sec As Long)
Dim t0 As Long
Dim DnCnt As Boolean
   Do
         t0 = Timer
          While Timer - t0 < Sec
              DoEvents
          Wend
         
            If Not DnCnt Then
               iValue = iValue + 1
               If iValue >= 10 Then
                  DnCnt = True
               End If
                Sheets(1).Range("a1").Value = iValue
            Else
               iValue = iValue - 1
               If iValue <= 1 Then
                  
                  DnCnt = False
                    If TimerStop Then
                        TimerStop = False
                        TimerEnable = False
                        Exit Do
                     End If
               End If
               Sheets(1).Range("a1").Value = iValue
            End If
            If Not TimerEnable Then Exit Do
   Loop
    Sheets(1).Range("a1").Value = iValue
End Sub

回復 2# GBKEE
謝謝版主

TOP

        靜思自在 : 君子如水,隨方就圓,無處不自在。
返回列表 上一主題