How to refer to QueryTable by name
I have a question about qy.WorkbookConnection and qy.Name where qy is defined as QueryTable. The qy.WorkbookConnection is 'con2' and the qy.Name is 'Query from MS Access Database_5'.
How can I change the SQL for this specific qy.WorkbookConnection or qy.Name? I can loop through all of the worksheets and all of the querytables searching for the specific connection or name, but I'd like to refer to the WorkbookConnection (or Name) directly by its name. Hope this isn't too confusing.
Thanks
Re: How to refer to QueryTable by name
Is this VB6 or some form of VBA?
Re: How to refer to QueryTable by name
Re: How to refer to QueryTable by name
Thread moved from the 'VB6' forum to the 'Office Development/VBA' forum (while VBA and VB6 have some similarities, they are not the same thing)
Re: How to refer to QueryTable by name
this should work to set a specific query table, by name, to an object
vb Code:
For Each q In Sheets(1).QueryTables
If q.Name = myName Then Exit For
Next
if the for each does not find a table by that name then q will be a nothing object on completion, else it will contain the querytable object
Re: How to refer to QueryTable by name
Thanks for reply. But I was asking if there was a way to directly refer to the QueryTable by name rather than looping through all the QueryTable's and checking their names.
Re: How to refer to QueryTable by name
no, index only
you could store the names in a collection