LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default Return First Line from a group of files

Thanks... worked like a charm.


On Dec 6, 5:19*pm, Joel wrote:
The code is looking at all *.txt files in ther directory FOLDER. *Change
Folder as required.

Sub GetFirstLine()

Folder = "C:\temp\"

Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

Set fsread = CreateObject("Scripting.FileSystemObject")

FName = Dir(Folder & "*.txt")
RowCount = 1
Do While FName < ""
* *Set fread = fsread.GetFile(Folder & FName)
* *Set tsread = fread.OpenAsTextStream(ForReading, TristateUseDefault)

* *InputLine = tsread.ReadLine
* *Range("A" & RowCount) = FName
* *Range("B" & RowCount) = InputLine

* *tsread.Close
* *FName = Dir()

* *RowCount = RowCount + 1
Loop
End Sub



"willwonka" wrote:
I have a folder with about 150textfiles. *I would like a macro that
would return thefirstlineof each of those files into a spreadsheet.


The files do share a comman name with a sequence number at the end.
For example, thefirstfilename would be:


210SHyyyy.mm.ddx.txt


where x starts at 0 and goes to 150


Is this possible?- Hide quotedtext-


- Show quotedtext-


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to put a line between each group? Holly Excel Discussion (Misc queries) 6 August 20th 07 09:16 PM
TWO FILES OPEN AT SAME TIME XLS:1 AND XLS:2 GROUP??? Jimbomini Excel Discussion (Misc queries) 4 August 23rd 06 08:20 PM
Pivot tables - Group Label on each line DrIan Excel Discussion (Misc queries) 3 August 8th 06 09:18 PM
Formula to return a value if any numbers in a group meet a criteri dcozzi Excel Worksheet Functions 3 April 13th 06 02:45 PM
Converting a group of lines into one line without merging THEFALLGUY Excel Discussion (Misc queries) 2 August 24th 05 06:45 PM


All times are GMT +1. The time now is 12:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"