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

  • Home
  • SEARCH
  • 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 7692295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:49:16+00:00 2026-05-31T20:49:16+00:00

I have about 600 text files. Each file contains 2 columns and is space

  • 0

I have about 600 text files. Each file contains 2 columns and is space delimited. Is there any way I can import all of them to the same excel spreadsheet?

I saw a post about this and used the following script but that didn’t work for me. It gived me User-defined type not defined

Sub ReadFilesIntoActiveSheet()
Dim fso As FileSystemObject
Dim folder As folder
Dim file As file
Dim FileText As TextStream
Dim TextLine As String
Dim Items() As String
Dim i As Long
Dim cl As Range

' Get a FileSystem object
Set fso = New FileSystemObject

' get the directory you want
Set folder = fso.GetFolder("D:\mypath\")

' set the starting point to write the data to
Set cl = ActiveSheet.Cells(1, 1)

' Loop thru all files in the folder
For Each file In folder.Files
    ' Open the file
    Set FileText = file.OpenAsTextStream(ForReading)

    ' Read the file one line at a time
    Do While Not FileText.AtEndOfStream
        TextLine = FileText.ReadLine

        ' Parse the line into | delimited pieces
        Items = Split(TextLine, "|")

        ' Put data on one row in active sheet
        For i = 0 To UBound(Items)
            cl.Offset(0, i).Value = Items(i)
        Next

        ' Move to next row
        Set cl = cl.Offset(1, 0)
    Loop

    ' Clean up
    FileText.Close
Next file

Set FileText = Nothing
Set file = Nothing
Set folder = Nothing
Set fso = Nothing

End Sub

`

Thanks for the help!

  • 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-05-31T20:49:17+00:00Added an answer on May 31, 2026 at 8:49 pm

    Most likely you need to set a reference to the Windows Scripting Host Object Model.

    To do this, from the Visual Basic Editor choose Tools/References, then scroll down to find “Windows Script Host Object Model”. Tick this box then press OK. Now try to run your code again.

    Additionally, I notice you mention that your data is split into two columns and space-delimited. You’ll need to replace the delimiter on the following line:

    Items = Split(TextLine, "|")
    

    With this:

    Items = Split(TextLine, " ")
    

    Finally, you’d be slightly better off replacing this:

    For i = 0 To UBound(Items)
      cl.Offset(0, i).Value = Items(i)
    Next
    

    With this:

    cl.Resize(1,UBound(Items)-LBound(Items)+1).value = Items
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of about 600 jobs that I can't delete from the
How hard is it to do? I have a text with about 600 characters,
I have a MS SQL DB with about 2,600 records (each one information on
I have about 100k Outlook mail items that have about 500-600 chars per Body.
I have about 200 Excel files that are in standard Excel 2003 format. I
I have about 50 images of 50 x 50 pixel size each. I want
I have found this great tutorial, about uploading files with a Flex app, using
I have this piece of Javascript code, which takes about 600 ms on every
I have about 150 000 rows of data written to a database everyday. These
I have about 10million values that I need to put in some type of

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.