Text File Import with Custom Delimiters

Import TXT or CSV files with custom column delimiters and save as formatted Excel workbook with automatic data type detection.

68 views

Perfect For:

  • Data migration
  • Legacy system exports
  • CSV conversion
  • Batch file processing
  • Database imports

PRO Template

Sign up for free to unlock the complete VBA code and access all templates

VBA Code (Preview)
Sign up to copy
' Text File Import with Custom Delimiters
' Import multiple text files and convert to Excel with specific column splits

Sub ImportTextFiles()
    ' Import text files with custom delimiters
    On Error GoTo ErrorHandler

    Application.ScreenUpdating = False

    ' Prompt for folder containing text files
    Dim folderPath As String
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Select Folder Containing Text Files"
        .Show
        If .SelectedItems.Count = 0 Then
            MsgBox "No folder selected.", vbExclamation
            Exit Sub
        End If
        folderPath = .SelectedItems(1)
    End With

    If Right(folderPath, 1) <> "" Then folderPath = folderPath & ""

    ' Get list of text files to import
    Dim fileName As String
    Dim fileCount As Integer
    fileCount = 0

    fileName = Dir(folderPath & "*.txt")

    Do While fileName <> ""
        ' Import each file
        Call ImportSingleFile(folderPath & fileName)
        fileCount = fileCount + 1
        fileName = Dir()
    Loop

    Application.ScreenUpdating = True

    If fileCount = 0 Then
        MsgBox "No text files found in selected folder.", vbInformation
    Else
        MsgBox "Successfully imported " & fileCount & " file(s)!", vbInformation
    End If

    Exit Sub

ErrorHandler:
    Application.ScreenUpdating = True
    MsgBox "Error importing files: " & Err.Description, vbCritical
End Sub

Sub ImportSingleFile(filePath As String)
    ' Import a single text file with custom delimiter
    On Error GoTo ErrorHandler

    ' Prompt for delimiter specification
    Dim delimiter As String

' ... 136 more lines hidden ...
'
' Sign up for free to view the complete code
' Visit: vbacode.io
Access all 45 templates
10 free AI generations/month
No credit card required

Related Topics

import text file csv delimiter conversion

Need Custom VBA Solutions?

Our AI-powered VBA generator can create custom code tailored to your specific requirements in seconds.

Generate Custom VBA Code