如題:我寫了一個簡單的VBA但是發現只要開始跑迴圈時,就不能開其他XLS檔與自己檔的其他sheets
Private Sub CommandButton1_Click()
Do While Range("B2") = 1
Range("A1") = Range("A2")
DoEvents
Loop
End Sub
我將程式修改成如下,結果程式變成不能跑了,而且在未修改前可以跑兩個程式,但開啟其他EXCEL檔後程式會變成跑到另一個新EXCEL做運算(ex,跑到book2.xls中做計數)
Option Explicit
Declare Function SetTimer _
Lib "user32" ( _
ByVal hWnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) _
As Long
Declare Function KillTimer _
Lib "user32" ( _
ByVal hWnd As Long, _
ByVal nIDEvent As Long) _
As Long
'EXCEL視窗的handle, id設為1, 每 0.2秒執行1次Asub程序
Sub StartAsub()
SetTimer Application.hWnd, 1, 200, AddressOf Asub
End Sub
Sub StopAsub()
KillTimer Application.hWnd, 1
End Sub
Sub StartBsub()
SetTimer Application.hWnd, 2, 500, AddressOf Bsub
End Sub
Sub StopBsub()
KillTimer Application.hWnd, 2
End Sub
Sub Asub()
With ActiveSheet.Workbooks("book1.xls").Sheets("sheet1").Range("a1")
.Value = .Value + 1
End With
End Sub
Sub Bsub()
With ActiveSheet.Workbooks("book1.xls").Sheets("sheet1").Range("b1")
.Value = .Value + 1
End With
End Sub作者: GBKEE 時間: 2010-10-3 06:32