How to Get Queries/Connection Name Using Excel VBA?

radian89

Board Regular
Joined
Nov 12, 2015
Messages
113
Hi Everyone,

I kinda lost here, how to Get each Queries/Connection Name and put it in a cell? Currently I use this to refresh each of the connection, and I want to put each connection name in a cell after it refreshed. can we do that?

1617450102234.png


VBA Code:
                '3. Refresh all query connections
                '------------------------------------------------------------------------------------------------
                    For Each objconnection In ThatWb.Connections
                    
                        'Get current background-refresh value
                        bbackground = objconnection.OLEDBConnection.BackgroundQuery
                        
                        'Temporarily disable background-refresh
                        objconnection.OLEDBConnection.BackgroundQuery = False
                       
                        'Refresh this connection
                        objconnection.Refresh

                        'I want to put the connection name in a cell for each of the connection here

                        'Set background-refresh value back to original value
                        objconnection.OLEDBConnection.BackgroundQuery = bbackground
                       
                       Next
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
VBA Code:
For Each objconnection In ThatWb.Connections
    Debug.Print objconnection.Item.Name
Next
is this what you are looking for
 
Upvote 0

Forum statistics

Threads
1,214,548
Messages
6,120,141
Members
448,948
Latest member
spamiki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top