shayanan
02-23-2021, 07:18 AM
I have 3 External web Connections. I use code below to start and stop automatically refresh, but it refreshed All connections.
I need 2 Things:
1- just Refreshing One of Connections: "ConnectionA".
2- Use a cell value to Assign Seconds to repeat refreshing. for example value of cell "A2" is 45, so auto refresh every 45 second.
Public RefreshTime As Double
Public Const Seconds = 30 'Input Refresh Interval in seconds
Sub StartRefreshLoop()
' User Message indicating loop is beginning
MsgBox "Refreshes will begin to occur at " & the designated interval of " & Seconds & " seconds"
' Call the first Refresh
Call StartRefreshes
End Sub
Sub StartRefreshes()
' Calculate Next Refresh Time
RefreshTime = Now + TimeSerial(0, 0, Seconds)
' Trigger a Refresh with OnTime function
Application.OnTime _
EarliestTime:=RefreshTime, _
Procedure:="RefreshConnections", _
Schedule:=True
End Sub
Sub RefreshConnections()
' Refresh Data Connections
ThisWorkbook.RefreshAll
' Start Timer Over Again
Call StartRefreshes
End Sub
Sub EndRefreshLoop()
' On Error Resume Next
Application.OnTime _
EarliestTime:=RefreshTime, _
Procedure:="RefreshConnections", _
Schedule:=False
' User Message indicating loop has ended
MsgBox "Refreshes are no longer occurring"
End Sub
I need 2 Things:
1- just Refreshing One of Connections: "ConnectionA".
2- Use a cell value to Assign Seconds to repeat refreshing. for example value of cell "A2" is 45, so auto refresh every 45 second.
Public RefreshTime As Double
Public Const Seconds = 30 'Input Refresh Interval in seconds
Sub StartRefreshLoop()
' User Message indicating loop is beginning
MsgBox "Refreshes will begin to occur at " & the designated interval of " & Seconds & " seconds"
' Call the first Refresh
Call StartRefreshes
End Sub
Sub StartRefreshes()
' Calculate Next Refresh Time
RefreshTime = Now + TimeSerial(0, 0, Seconds)
' Trigger a Refresh with OnTime function
Application.OnTime _
EarliestTime:=RefreshTime, _
Procedure:="RefreshConnections", _
Schedule:=True
End Sub
Sub RefreshConnections()
' Refresh Data Connections
ThisWorkbook.RefreshAll
' Start Timer Over Again
Call StartRefreshes
End Sub
Sub EndRefreshLoop()
' On Error Resume Next
Application.OnTime _
EarliestTime:=RefreshTime, _
Procedure:="RefreshConnections", _
Schedule:=False
' User Message indicating loop has ended
MsgBox "Refreshes are no longer occurring"
End Sub