Name

querytable.RefreshPeriod [= setting]

Synopsis

Sets or returns the number of minutes between automatic refreshes. The default is 0, for no automatic refreshing. You can set automatic refreshing on synchronous or asynchronous queries. RefreshPeriod is ignored for query tables created from recordsets.

The following code creates a query table from an ODBC data source and sets the query table to refresh once a minute:

    strConn = "ODBC;DRIVER=SQL Server;SERVER=.;UID=Jeff;APP=Microsoft Office " & _
    "XP;WSID=WOMBAT2;DATABASE=pubs;Trusted_Connection=Yes"
    strSQL = "SELECT titles.title, titles.price, titles.pubdate, titles.ytd_sales
    FROM pubs.dbo.titles titles"
    Set qt = ActiveWorksheet.QueryTables.Add(strConn, [QueryDestination], strSQL)
    qt.RefreshPeriod = 1
    qt.Refresh

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.