Forum

VBA to Create Data ...
 
Notifications
Clear all

VBA to Create Data Connection for All Tables

6 Posts
2 Users
0 Reactions
217 Views
(@digaloguapo)
Posts: 23
Eminent Member
Topic starter
 

Hi Forum Members,

Power Query is very useful in merging data but my big problem is when I have several tables to merge. Adding each one to a New Connection is a very slow process.

I'm wondering if anyone knows of a VBA solution that can identify every table (even on different Worksheets) within a workbook AND automatically create a data connection in Power Query?

 
Posted : 23/02/2017 8:22 pm
(@mynda)
Posts: 4761
Member Admin
 

Hi Digalo,

Yes, if you use From File > From Excel you can bring all of the sheets/tables/named ranges in, in one go. Make sure you check the 'Select Multiple Items' check box in the From File Navigator once you've chosen the workbook.

Mynda

 
Posted : 23/02/2017 11:59 pm
(@digaloguapo)
Posts: 23
Eminent Member
Topic starter
 

Thanks Mynda. I appreciate your fast response.

So your solution works for a closed workbook, but does it work for an open workbook? If I currently have a Excel workbook open, I'm look for a way to add all tables/named ranges to a connection at once, instead of doing it one by one.

 
Posted : 24/02/2017 1:58 am
(@mynda)
Posts: 4761
Member Admin
 

You can use the Excel.Workbook function in a blank query.

In the formula bar type:

=Excel.Workbook()

Press enter.

 
Posted : 24/02/2017 7:13 am
(@digaloguapo)
Posts: 23
Eminent Member
Topic starter
 

Thanks Mynda,

I couldn't get your suggestion to work, but Excel.CurrentWorkbook() did grab a list of tables/sheets.

This gets me to about 80% of what I wanted.

I appreciate your help!

 
Posted : 25/02/2017 1:04 am
(@mynda)
Posts: 4761
Member Admin
 

Ah, yes sorry. I left out the 'current' part of the function 🙂 Glad you figured it out.

Mynda

 
Posted : 27/02/2017 10:46 pm
Share: