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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
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,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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