I am having a strange problem with my excel app. The question is very simple: I have a workbook with several queries, and I need to refresh only some of them via VBA. Trying not to run into stupid errors (misspelled names...), I ran a simple proc to get the names of the queries, as follows:
So far, everything is OK, I get the list of the names of the queries (query1, query2, and so on). Now to refresh the queries I need, I just code
and this does not work, it fails with the error "runtime error 1004, application defined or object defined error", with every query name I use. After a lot of thinking and searching for help, I found the way out (NOT the explanation). I replaced the queries with the connections. So I ran the test proc:
and I got the list of the names of the connections,in the format:
query - query1
query - query2
....
and now, coding
no error any longer.
I find this disturbing, since I don't understand what is going on. Why Excel throws an error with query names? In addition using excel autocompletion, it appears that with connection you could not use "names", but only Index, whereas with query you can use both.But using the index (1,2...) with query does not work anyhow, whereas with connections the name works. Does someone have an explanation other than Microsoft got confused?
Screenshot 2025-05-31 203353.png
Screenshot 2025-05-31 204732.png
Bookmarks