| Public Sub RefreshIntradayData() ' The VBA classes (e.g., 'OxlQuery', 'OxlQueryList') in this macro are plain VBA classes which are ' added to your workbook when you select {'Tools' -> 'Configure workbook for VBA API'} from optimal(xl)'s ' menu. These are not fragile type-library references and have no compile-time dependencies, i.e., ' teammates can always open this workbook without having VBA references blow up. ' This type is a read-only, record-style plain VBA class that represents a single in-cell query and makes ' it easy for your macros to get information about the in-cell SQL, the structured metadata that accompanies ' it as an in-cell comment, and the on-sheet table of data that the SQL produces. Dim query As OxlQuery
' This is a strongly-typed collection class to hold one or more individual 'OxlQuery' types. This collection ' will hold all queries in this workbook, and from those we'll pick out the ones that hit tables with ' 'intraday=true' as part of the Snowflake table comment. Dim allQueries As OxlQueryList
' Another 'OxlQuery' collection class, this one will hold a subset of all queries, i.e., those whose ' Snowflake table comment contains the text 'intraday=true'. Dim intradayQueries As OxlQueryList ' Instantiate the collection classes. Set allQueries = New OxlQueryList Set intradayQueries = New OxlQueryList ' This method will find and load, as OxlQuery objects, all the in-cell SQL queries in your workbook allQueries.LoadAllInWorkbook ThisWorkbook ' Iterate over each in-cell SQL query in this workbook; nothing within this loop hits Snowflake. For Each query In allQueries.AsEnumerable() ' Whenever an in-cell SQL statement is executed, Snowflake table comments for tables represented ' in the query are added to the structured metadata that accompanies the SQL cell as a cell comment. ' Here we access that metadata to see if this particular query hits an 'intraday=true' table. If query.TableCommentsAll.ContainsCaseInsensitive("intraday=true") Then intradayQueries.Add query End If Next ' This is the only line of code in this macro that hits Snowflake; this runs the intra-day queries and ' updates your sheets with the results. OxlSnowflake.RunParallel intradayQueries End Sub |