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
 

dreanged

New Member
Joined
Jan 29, 2014
Messages
5
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?
 

Forum statistics

Threads
1,081,526
Messages
5,359,287
Members
400,524
Latest member
Excelbat

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top