Share via

How do to run VBA code after an automatic data connection update that has been set to run every 5 minutes?

Anonymous
2014-02-05T21:06:44+00:00

I am trying to have a data connection to a website that will automatically update every 5 min.  After this update I would like to have a VBA Macro run to analyze the new data.  does anyone know how to have the code run after that Auto Update?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2014-02-05T23:00:05+00:00

You could use the Worksheet_Change event to detect when the data is updated, and then run your macro.  Simple example below assumes you have a QueryTable (i.e. data connection to the web) on Sheet1.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim myConn As QueryTable

    Set myConn = Me.QueryTables(1)

    With myConn

        If (Not Intersect(Target, Range(.Destination.Address)) Is Nothing) Then

            MsgBox "The data was updated"

            Call MyMacro(myParam1, myParam2)

        End If

    End With

End Sub

HTH,

Eric

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful