How to Get Queries/Connection Name Using Excel VBA?

radian89

Board Regular
Joined
Nov 12, 2015
Messages
112
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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

jsb1921

Board Regular
Joined
Aug 14, 2020
Messages
70
Office Version
  1. 2007
Platform
  1. Windows
  2. Web
VBA Code:
For Each objconnection In ThatWb.Connections
    Debug.Print objconnection.Item.Name
Next
is this what you are looking for
 

Watch MrExcel Video

Forum statistics

Threads
1,129,476
Messages
5,636,556
Members
416,923
Latest member
jarri

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
Top