以下代码无法正常运行。问题是,在前一行给出的命令完全完成输出到屏幕之前,似乎下一行是执行的。
那么,在执行下一行之前,什么命令强制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
答案 0 :(得分:0)
抱歉,低质量的答案,其余的StackOverflow ...在评论中解决了这个问题,并提供了答案,因此问题不会保持列为打开。
见:How to give a time delay of less than one second in excel vba? - Cyril 54分钟前