0
當工作表打開時,在宏下面運行。問題在於,無論何時我更改單元格中的值或執行任何事件,宏都會再次啓動。如何預防它?VBA只運行宏一次
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
Dim i As Long
i = Application.WorksheetFunction.CountIf(Range([W2], Cells(Rows.Count, "W").End(xlUp)), "tak")
Worksheets("Arkusz1").Range("AZ1").Value = i
If Worksheets("Arkusz1").Range("AZ1").Value > 0 Then
MsgBox "Sa " & i & " wózki do przeglądu"
Else
MsgBox "Nie ma wózków do przeglądu"
End If
Application.EnableEvents = True
End Sub
感謝將其更改爲Workbook_Open解決了它。 – eurano