import files to individual tabs

quando

New Member
Joined
Apr 30, 2009
Messages
9
How can I automatically import tsv (tab separated values) files into a single workbook, where each file will be on its own tab?

Thanks,
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Assuming that the tab-delimited files are all located in a separate subfolder (and no other files are in that subfolder) and you will provide the name of that subfolder (in 2nd line of the code), this code should do the trick:

Code:
Option Explicit
Const TSV_FOLDERNAME = "{you need to provide the path name"
Sub ImportTABDelimitedFiles()
 
    Dim currentWb As Workbook
    Set currentWb = ActiveWorkbook
 
    Dim fs As Object
    Dim objFolder As Object
    Dim objFile As Object
 
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set objFolder = fs.GetFolder(TSV_FOLDERNAME)
 
    For Each objFile In objFolder.Files
        Workbooks.OpenText Filename:= _
            objFile.Path, _
            Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
            xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
            Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
            Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
        Sheets(1).Copy After:=currentWb.Sheets(Sheets.Count)
        Workbooks(Workbooks.Count).Close (False)
    Next
 
End Sub

Hope this helped,
Rolf
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,246
Members
449,075
Latest member
staticfluids

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