لا يعمل الرمز أدناه بشكل صحيح. المشكلة هي أنه يبدو أن السطر التالي يتم تنفيذه قبل أن ينهي الأمر الذي أعطاه السطر السابق الإخراج إلى الشاشة تمامًا.
لذا ، ما الأمر الذي يفرض على Excel الانتظار تمامًا حتى ينتهي الإجراء الفرعي تمامًا قبل تنفيذ السطر التالي؟
#If VBA7 Then
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
#Else
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
#End If
Sub SweepLinesAndPaintYellowActiveCell()
lastline= Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lastline
Cells(i, 1).Select
ActiveCellYellow
Sleep 25
ActiveCellWhite
Next i
End Sub
Sub ActiveCellYellow()
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub
Sub ActiveCellWhite()
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub