VBA to Add Connection to Separate Workbook

PGBrown

New Member
Joined
Jul 17, 2013
Messages
16
I have 2 workbooks (Workbook A and Workbook B). Workbook A contains data and Workbook B has a series of pivot tables and pivot charts that are linked to that data. I'm trying to use vba to create the connection to Workbook A, refresh the data, then delete the connection. I'm running into trouble creating the connection. After the .connections.addfromfile line, a dialog box pops up asking me to Select Table and it lists 3 available tables. The code pauses at this point and waits for me to select one of the tables. I've tried SendKeys, but since it pauses the code, it doesn't execute that lines. Any help would be greatly appreciated! The code is short and simple enough, it seems the solution should be pretty straight forward, I just can't find it.

Code:
Workbooks("Test Connection.xlsm").Connections.AddFromFile _
    "C:\Users\user\Desktop\New folder (2)\Data.xlsx"
ActiveWorkbook.RefreshAll
ActiveWorkbook.Connections("Data").Delete
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Having the same issue using Connections.AddFromFile - getting the dialog box with "Select Table". What VBA code is required to automatically select the Table needed?
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

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