QueryTables - Data into another workbook

CMIIandExcel

Board Regular
Joined
Sep 4, 2009
Messages
190
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.

Regards

Mike

Code:
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:= _
        wsDestination.Range(strDestinationCell))
        .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
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

CMIIandExcel

Board Regular
Joined
Sep 4, 2009
Messages
190
Opps

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

That is what happens on 3 hours sleep:eek:

Regards

Mike
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,686
Messages
5,833,119
Members
430,194
Latest member
dbow2226

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
Top