+ Reply to Thread
Results 1 to 6 of 6

Copying multiple text files from a folder into excel

Hybrid View

  1. #1
    Registered User
    Join Date
    02-19-2014
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Copying multiple text files from a folder into excel

    Haven't started on it yet.
    I'm currently at work and will write the script when I get home tonight.

    Google has been great in providing the solutions for the intermediate steps, but I just can't get the looping part down.

  2. #2
    Registered User
    Join Date
    02-19-2014
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Copying multiple text files from a folder into excel

    Here is a sample of the text file that I am using:

    Company Name: Pears Galore
    Revenue: $500,000

    The code

    Sub GetInfoFromText()
      Dim X As Long, FilePathAndName As String, TotalFile As String, FileNum As Long, Arr() As String
      Dim CompanyName As String, Revenue As String
        
      ' Get path and filename by whatever means you do now
      FilePathAndName = "C:\Users\revenue.txt"
      
      ' Read entire file into TotalFile variable
      FileNum = FreeFile
      Open FilePathAndName For Binary As #FileNum
        TotalFile = Space(LOF(FileNum))
        Get #FileNum, , TotalFile
      Close #FileNum
      ' Get Company Name
      Arr = Split(TotalFile, "Company Name: ")
      CompanyName = Split(Arr(1), vbCrLf)(0)
      
      ' Get Revenue
      Arr = Split(TotalFile, "Revenue: ")
      Revenue = Split(Arr(1), vbCrLf)(0)
             
        ActiveCell = CompanyName
        ActiveCell.Offset(1) = Revenue
             
    End Sub
    I took this code off someone else and edited to make it mine. However, I am not sure what can be done to make it loop for multiple text files, and insert the revenue figures into a column.
    Is it also possible to automatically input the file path and name? or would this have to be done manually?
    Last edited by WinningKing; 02-20-2014 at 08:49 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 09-16-2013, 02:24 AM
  2. copying data from excel files in a source folder to target folder
    By Javed07 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2013, 04:27 PM
  3. Multiple Files in a folder - Copying to one file
    By ingwingfingerling in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-31-2012, 04:57 PM
  4. Copying data from multiple files in a folder to a master file
    By kjshep in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-22-2012, 12:31 PM
  5. Replies: 1
    Last Post: 02-29-2012, 01:15 PM

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