+ Reply to Thread
Results 1 to 2 of 2

is it possible... (multiple input+naming)

  1. #1
    Registered User
    Join Date
    07-14-2006
    Posts
    15

    is it possible... (multiple input+naming)

    Is it possible to make a macro that inputs all text files from the directory the workbook is located in and put the files name (text01.txt) as the first cell of the column the files data is inputed into? resulting in something like this:

    test01.txt test02.txt test03.txt
    xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx

  2. #2
    Bernie Deitrick
    Guest

    Re: is it possible... (multiple input+naming)

    Try the macro below. Store it in a workbook in the folder with the text files that you want to put
    into one file.

    HTH,
    Bernie
    MS Excel MVP

    Sub ConsolidateTextFiles()
    Dim myBook As Workbook
    Dim myCalc As XlCalculation

    With Application
    .EnableEvents = False
    .DisplayAlerts = False
    myCalc = .Calculation
    .Calculation = xlCalculationManual
    End With

    On Error Resume Next
    With Application.FileSearch
    .NewSearch
    'This workbook must be stored in the folder of interest
    .LookIn = ThisWorkbook.Path
    .SearchSubFolders = False
    .Filename = "*.txt"
    If .Execute() > 0 Then
    For i = 1 To .FoundFiles.Count
    Set myBook = Workbooks.Open(.FoundFiles(i))
    myBook.Worksheets(1).Range("A1").CurrentRegion.Copy _
    ThisWorkbook.Sheets(1).Cells(2, i)
    ThisWorkbook.Sheets(1).Cells(1, i).Value = _
    Replace(.FoundFiles(i), .LookIn & "\", "")
    myBook.Close False
    Next i
    Else: MsgBox "There were no files found."
    End If
    End With
    With Application
    .EnableEvents = True
    .DisplayAlerts = True
    .Calculation = myCalc
    End With

    End Sub






    "rbmcclen" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Is it possible to make a macro that inputs all text files from the
    > directory the workbook is located in and put the files name
    > (text01.txt) as the first cell of the column the files data is inputed
    > into? resulting in something like this:
    >
    > test01.txt test02.txt test03.txt
    > xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx
    >
    >
    > --
    > rbmcclen
    > ------------------------------------------------------------------------
    > rbmcclen's Profile: http://www.excelforum.com/member.php...o&userid=36367
    > View this thread: http://www.excelforum.com/showthread...hreadid=563666
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1