Results 1 to 4 of 4

Thread: Vba To Refresh Specific External Connections

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Feb 2021
    Posts
    5
    Location

    Vba To Refresh Specific External Connections

    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
    Last edited by Aussiebear; 02-24-2025 at 02:56 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •