QueryTables - Data into another workbook


Board Regular
Sep 4, 2009
Hi all

I have 3 workbooks:
1 - Macros are in a Control Workbook
2 - Data source which is a CSV file
3 - Destination for the data which is a preformatted template

all three workbooks are open at the time of the code running

I am using the code below to extract the data from the source workbook and then add this data into the template file.

The problem I have is that I cannot get the data into the template(Destination sheet), it places the data into range A1 of the source file

What do i need to change to place the data into another workbook?? i have tried a few things but nothing seems to work.



Public Sub GetDelimitedData(wbdestination As Workbook, wsDestination As Worksheet, strDestinationCell As String, _
                                strSourceFileAddress As String, arrDataTypes() As Long)
    With wsDestination.QueryTables.Add(Connection:= _
        "TEXT;" & strSourceFileAddress, Destination:= _
        .Name = ""
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = False
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 2
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = arrDataTypes()
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
End Sub

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.


Board Regular
Sep 4, 2009

I found the issue, i was passing the wrong sheet to the call:oops::oops:

That is what happens on 3 hours sleep:eek:



Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...