How to import multiple text files to multiple sheets?
Supposing, there are multiple text files in a folder of your computer, now, you want to import these text files to an Excel workbook, and place each text file into separate worksheets. Copying and pasting each text file to the worksheet one by one will waste lots of time, here, I can talk about some tricks for you to solve this problem.
Import multiple text files to separate worksheets with VBA code
Split a workbook to multiple separate text / pdf / csv / xlsx files with Kutools for Excel
Import multiple text files to separate worksheets with VBA code
The following VBA code may help you to import each text file into separate sheets within a new workbook at once, please do as follows:
1. Hold down the ALT + F11 keys in Excel to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Import multiple text files to separate worksheets:
Sub CombineTextFiles()
'updateby Extendoffice
Dim xFilesToOpen As Variant
Dim I As Integer
Dim xWb As Workbook
Dim xTempWb As Workbook
Dim xDelimiter As String
Dim xScreen As Boolean
On Error GoTo ErrHandler
xScreen = Application.ScreenUpdating
Application.ScreenUpdating = False
xDelimiter = "|"
xFilesToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt", , "Kutools for Excel", , True)
If TypeName(xFilesToOpen) = "Boolean" Then
MsgBox "No files were selected", , "Kutools for Excel"
GoTo ExitHandler
End If
I = 1
Set xTempWb = Workbooks.Open(xFilesToOpen(I))
xTempWb.Sheets(1).Copy
Set xWb = Application.ActiveWorkbook
xTempWb.Close False
xWb.Worksheets(I).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, _
Comma:=False, Space:=False, _
Other:=True, OtherChar:="|"
Do While I < UBound(xFilesToOpen)
I = I + 1
Set xTempWb = Workbooks.Open(xFilesToOpen(I))
With xWb
xTempWb.Sheets(1).Move after:=.Sheets(.Sheets.Count)
.Worksheets(I).Columns("A:A").TextToColumns _
Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, _
Comma:=False, Space:=False, _
Other:=True, OtherChar:=xDelimiter
End With
Loop
ExitHandler:
Application.ScreenUpdating = xScreen
Set xWb = Nothing
Set xTempWb = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description, , "Kutools for Excel"
Resume ExitHandler
End Sub
3. After pasting the above code, press F5 key to run this code, and in the popped out window, please specify the folder which contains the text files, go to the folder to select the text files you want to import to the worksheets, see screenshot:
4. Then click Open button, all the selected text files have been imported into a new workbook and each file located in one worksheet individually.
5. At last, you can save the new workbook as you need.
Split a workbook to multiple separate text / pdf / csv / xlsx files with Kutools for Excel
Sometimes, you may need to do some opposite operations of above task, that is to say, you need to split a workbook to separate text files. Kutools for Excel’s Split Workbook utility can help you to solve this job quickly and easily.
Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. |
After installing Kutools for Excel, please do as follows:( Free Download Kutools for Excel Now! )
1. Activate the workbook that you want to split to multiple text files.
2. Click Enterprise > Workbook > Split Workbook, see screenshot:
3. In the Split Workbook dialog box:
(1.) Check the worksheets that you want to split.
(2.) Check Specify save format, then choose the file format that you want to save, for example, you can choose txt, csv, pdf, xlsx or xls file format as you need.
(3.) Then click Split button, in the following prompt box specify a folder to output the separate files.
![]() |
![]() |
![]() |
4. Then click OK button, and your selected worksheets will be split and save to your desired folder with the format as you need.
Free Download Kutools for Excel Now!
The Best Office Productivity Tools
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
- Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
- Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
- Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
- Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
- Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
- Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
- Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
- Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
- More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!









