How to import all text files (column wise) from a folder?

Amit1

New Member
Joined
Jul 6, 2012
Messages
23
Dear Friends,
I am trying to import several text files (around 80 in number) at a time from a folder. The data should be loaded to the excel sheet column wise. I was able to get the macro for loading it one by one where every time i have change the name of the file in the path.
The code in provided below:

Code:
Sub DataLoad()
'
' DataLoad Macro
' DataLoad
'
' Keyboard Shortcut: Ctrl+q
'
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Documents and Settings\Administrator\Desktop\target folder" _         '(I'm mentioning the file   name here after target folder)
        , Destination:=Range("$A$1"))
        .Name = "data1"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
    Range("B1").Select
    ActiveCell.FormulaR1C1 = ""
    Range("B1").Select
    ActiveSheet.Paste
    Columns("B:B").EntireColumn.AutoFit
    ActiveWorkbook.Save
    ActiveWorkbook.Save
    Range("C1").Select
End Sub

How to load all the files at a time in a Excel sheet?
Looking forward for your suggestions.
 
Your problem is much more involved/complex than first presented, and I probably do not have the time to commit to that right now. If you are actually looking for someone to do this whole thing for you, your best bet may be to try to enlist some paid consulting services (see: Excel Consultant | Excel Consulting | Microsoft Office Consultants).

If you are hoping to do this yourself with a little assistance, your best bet may be instead of trying to cram everything in one daunting post that might scare a lot of people off, to break it up into multiple questions, i.e. one for the import of the different format, one for the loop, one for automation, etc. The general rule of thumb is that all directly related follow-up questions (that are directly dependent on the previous question) should be posted to the same thread, but brand new questions not dependent upon previous answers can be posted in their own threads (even if it is involved on the same project on your end).
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,215,429
Messages
6,124,834
Members
449,192
Latest member
mcgeeaudrey

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