Hi,
try the "sleep"-function:
Code:Private Declare PtrSafe Sub Sleep Lib "kernel32.dll" ( _ ByVal dwMilliseconds As Long) Public Sub mySleep() 'your code Call Sleep(2000) '2000 Millisekunden Pause End Sub
only works once ?
all I want is a refresh every 2 seconds as this spreadsheet is a display only
another spreadsheet is maintained
I would like a looped code that waits 2 seconds then refreshes the links e.g calculate then waits 2 seconds then refreshes - basically a loop
Private nextTime As Date
Sub startit()
nextTime = Now + TimeSerial(0,0,2), "repeatit"
Application.OnTime nextTime, "repeatit"
end Sub
Sub repeatit()
' do whatever you need here to "refresh the links"; perhaps:
' Application.Calculate
' then...
nextTime = Now + TimeSerial(0,0,2), "repeatit"
Application.OnTime nextTime, "repeatit"
End Sub
Sub stoptit
On Error Resume Next
Application.OnTime nextTime, "repeatit",, False
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
stopit
End Sub
A Sleep loop would never leave VBA. Perhaps you want the following in a normal module (not a worksheet module):
Code:Private nextTime As Date Sub startit() nextTime = Now + TimeSerial(0,0,2), "repeatit" Application.OnTime nextTime, "repeatit" end Sub Sub repeatit() ' do whatever you need here to "refresh the links"; perhaps: ' Application.Calculate ' then... nextTime = Now + TimeSerial(0,0,2), "repeatit" Application.OnTime nextTime, "repeatit" End Sub Sub stoptit On Error Resume Next Application.OnTime nextTime, "repeatit",, False End Sub
To avoid having to remember to execute "stopit" manually, you also might want to put the following into the ThisWorkbook module:
Code:Private Sub Workbook_BeforeClose(Cancel As Boolean) stopit End Sub
in the vba editor these lines are red font
nextTime = Now + TimeSerial(0,0,2), "repeatit"
Calculate
Application.Wait (Now + TimeValue("0:00:05"))
Calculate
Application.Wait (Now + TimeValue("0:00:05"))
[....]
but not needing so many lines hahahaha
also the ability to pause the code by clicking a shape then after so many seconds it reverts to the refresh again