Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Extracting Text Data to Excel

I have been struggling now for a few days, so time to ask the experts. My
problem is this;

I have 46 txt files each in exactly the same format and layout each with
different file names,
I need to be able to open all the files in th efolder Without specifying file
names,
Then to be able to extract the 3rd and 46th line from each txt file,
I then want to paste these 2 lines into a workbook leave a space and then
paste the next 2 lines and so on,
and finally the two lines will need formatted to "text to columns\fixed width\


can anyone help?

many thanks

David

--
Message posted via http://www.officekb.com
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Extracting Text Data to Excel

I'm assuming that the 46 text files are all in the same folder (in my
example, C:\Test), that they all have a file extension of "txt" and that no
other files in that folder have a txt extension. In the TextToColumns
routine, you will need to provide more Array information to get a decent
result.

Sub FetchSomeLines()

Dim R As Integer
Dim rngA As Range
Dim rngB As Range

Const ForReading = 1

strFldPath = "C:\Test"
R = 1

Set FSO = CreateObject("Scripting.FileSystemObject")
Set objFldr = FSO.GetFolder(strFldPath)

For Each objFile In objFldr.Files
If FSO.GetExtensionName(objFile) = "txt" Then
Set objTextFile = FSO.OpenTextFile(objFile, ForReading)
objTextFile.ReadLine
objTextFile.ReadLine
Cells(R, 1).Value = objTextFile.ReadLine
R = R + 1

For I = 1 To 42
objTextFile.ReadLine
Next I

Cells(R, 1).Value = objTextFile.ReadLine
R = R + 2

objTextFile.Close

End If
Next objFile

Set rngA = Range("A1").EntireColumn
Set rngB = Range("B1")

rngA.TextToColumns Destination:=Range("B1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(0, 1), TrailingMinusNumbers:=True

rngA.Delete

End Sub





Steve


"Ozzie via OfficeKB.com" <u18021@uwe wrote in message
news:5b4669a0bbeff@uwe...
I have been struggling now for a few days, so time to ask the experts. My
problem is this;

I have 46 txt files each in exactly the same format and layout each with
different file names,
I need to be able to open all the files in th efolder Without specifying
file
names,
Then to be able to extract the 3rd and 46th line from each txt file,
I then want to paste these 2 lines into a workbook leave a space and then
paste the next 2 lines and so on,
and finally the two lines will need formatted to "text to columns\fixed
width\


can anyone help?

many thanks

David

--
Message posted via http://www.officekb.com



Reply
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
extracting data and text. Aligahk06[_2_] Excel Discussion (Misc queries) 2 November 2nd 09 01:11 AM
Extracting Data from a string of text in a cell swalker Excel Worksheet Functions 4 August 7th 08 10:52 PM
Extracting Numeric Data from a Delimited Text String [email protected] Excel Worksheet Functions 5 February 10th 06 10:29 PM
extracting text data in a cell gareth1983 Excel Worksheet Functions 2 June 6th 05 02:08 AM
extracting data from a text string of varying length andy from maine Excel Discussion (Misc queries) 4 March 28th 05 07:11 PM


All times are GMT +1. The time now is 02:56 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"