Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7776781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:57:58+00:00 2026-06-01T17:57:58+00:00

In Excel 2010 I want to load all text files data from a folder

  • 0

In Excel 2010 I want to load all text files data from a folder to one Worksheet.

Each sheet should have data of one text file.

Each sheet is pipe delimited with header on first Row.

Update Macro

Sub LoadTextFilesLoop()
    Dim objFSO As Object
    Dim objFolder As Object
    Dim objFile As Object
    Dim ws As Worksheet

    Set objFSO = CreateObject("Scripting.FileSystemObject")
     'Get the folder object associated with the directory
    Set objFolder = objFSO.GetFolder("C:\Export\")
     'Loop through the Files collection
    For Each objFile In objFolder.Files
    NewFileImport (objFile.Name)
    Next
     'Clean up!
    Set objFolder = Nothing
    Set objFile = Nothing
    Set objFSO = Nothing
End Sub

Sub NewFileImport(FileName)
    Sheets.Add After:=Sheets(Sheets.Count)
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Export\FileName", _
        Destination:=Range("$A$1"))
        .Name = FileName
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 65001
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileOtherDelimiter = "|"
        .TextFileColumnDataTypes = Array(1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
End Sub

The loop is not loading the data.

I still have to figure out how I can get the Number of Columns in each file.

.TextFileColumnDataTypes = Array(1, 1, 1)

This line tells three columns in this file. This should vary based on the file columns.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:57:59+00:00Added an answer on June 1, 2026 at 5:57 pm

    Finally I got this worked
    here is my Macro for it.

    Sub LoadTextFilesLoop()
    Dim objFSO As Object
        Dim objFolder As Object
        Dim objFile As Object
        Dim ws As Worksheet
    
        Set objFSO = CreateObject("Scripting.FileSystemObject")
         'Get the folder object associated with the directory
        Set objFolder = objFSO.GetFolder("C:\Export\")
         'Loop through the Files collection
        For Each objFile In objFolder.Files
        NewFileImport (objFile.Name)
        Next
         'Clean up!
        Set objFolder = Nothing
        Set objFile = Nothing
        Set objFSO = Nothing
        End Sub
    
    Sub NewFileImport(FileName)
    Dim fName As String
    fName = Left(FileName, Len(FileName) - 4)
    Sheets.Add After:=Sheets(Sheets.Count)
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;C:\Export\" + FileName, _
            Destination:=Range("$A$1"))
            .Name = fName
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 65001
            .TextFileStartRow = 1
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = False
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = False
            .TextFileOtherDelimiter = "|"
            .TextFileColumnDataTypes = Array(1, 1, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
        ActiveSheet.Select
        ActiveSheet.Name = Left(fName, 31)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel 2010 workbook for financial records. On one worksheet, I have
Excel (2010) has functionality to create pivot tables from an external data source like
I want to create a excel 2010 file from C# so what will be
I want to support copy/paste functionality of Excel data from the windows clipboard onto
I want to connect to the access 2010 database from excel.I am using VBA.I
I have published my Excel workbook (which is one sheet with pivot-data linked to
I use VS 2010 for creating Excel 2007 xltx template. I want to remove
I am migrating some spreadsheets from Excel 2003/WinXP to Excel 2010/Win7. Some spreadsheets use
In a cell in Excel sheet I have a Date value like: 01/01/2010 14:30:00
I need to read from and write to Excel spreadsheets using Delphi 2010. Nothing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.