Reputation: 25
I have multiple web query tables in an Excel spreadsheet and I can refer to them in vba using QueryTable(1), QueryTable(2), etc.
I have some vba code that is used to refresh one of these tables, please see below. However, the problem is that every time I create a new web query table, the table's QueryTable number changes (i.e., n keeps changing for QueryTable(n) for a selected table). Is there a better way to refer to a specific web query table other than referring it as QueryTable(1)? Thanks.
main_workbook.Worksheets("Input ID").QueryTables(1).Refresh (False)
Upvotes: 0
Views: 528
Reputation: 308
Maybe...
For i = 1 To main_workbook.Worksheets("Input ID").QueryTables.Count Step 1
main_workbook.Worksheets("Input ID").QueryTables(i).Refresh (False)
Next i
Upvotes: 1