I have a excel document that has multiple metrics on multiple worksheets within the workbook. I have the code that cycles through each of the worksheets, the only problem I'm having is refreshing the database queries in the worksheet every few minutes.
The code I have so far is below, It starts teh database connection but there's no pause for the database to update the worksheet. I'm not sure how to make it show the new database values in the sheet.
Sub SwitchingSheets()
Dim wSheet As Worksheet
Dim iLoop As Integer
Dim i As Integer
iLoop = 2
For i = 1 To iLoop
For Each wSheet In Worksheets
NewHour = Hour(Now)
NewMinute = Minute(Now)
NewSecond = Second(Now) + 1
WaitTime = TimeSerial(NewHour, NewMinute, NewSecond)
wSheet.Select
Application.Wait WaitTime
Next wSheet
Next i
Run "UpdateAll"
End Sub
Sub UpdateAll()
ActiveWorkbook.RefreshAll
Run "SwitchingSheets"
End Sub
Option Explicit Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Sub Timer() ActiveWorkbook.RefreshAll Run "SwitchingSheets" Sleep 30 Call Timer End Sub
There is a property within the query, however, that says "Refresh every X minutes", and gives you the choice to enter the number of minutes. Are you needing something different?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks