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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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
 
Upvote 0

Forum statistics

Threads
1,214,883
Messages
6,122,077
Members
449,064
Latest member
MattDRT

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