A couple of months ago, I found some code online to create a delay when running VBA code, called SleepSub. I needed to use it because on Excel for Mac, some labels on my UserForms were not updating on the screen, even when I would use the Repaint method. (I think the labels were changing too fast for Excel to properly update them, though I never had that problem on Windows.) I found that if I called SleepSub on a Mac, the labels WOULD be updated on the screen.
On Excel 2011 for Mac, that sub just generated an overflow error. I have run this sub many times before without that error. What's worse is, I can't get it to repeat the error. Here's the full code of the sub:
The sub is inside a standard module. I call the sub from within a UF module, like so:
Anyone have any idea why I would sometimes receive an overflow error in SleepSub?
On Excel 2011 for Mac, that sub just generated an overflow error. I have run this sub many times before without that error. What's worse is, I can't get it to repeat the error. Here's the full code of the sub:
Code:
Sub SleepSub(vSeconds As Variant)
'this sub will delay the code running for however many seconds are in vSeconds.
Dim t0 As Single, t1 As Single
t0 = Timer
Do
t1 = Timer
If t1 < t0 Then t1 = t1 + 86400 'Timer overflows at midnight
DoEvents 'optional, to avoid excel freeze while sleeping
Loop Until t1 - t0 >= vSeconds
End Sub
The sub is inside a standard module. I call the sub from within a UF module, like so:
Code:
Sub UpdateStatusLabel(PercentFinished As Integer)
Me.StatusLabel.Caption = PercentFinished & "% complete"
Me.Repaint
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL] Mac Then
SleepSub(0.05)
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL] If
End Sub
Anyone have any idea why I would sometimes receive an overflow error in SleepSub?