PDA

View Full Version : How to Extract Title from a Text file and Paste to Excel



swaggerbox
05-03-2013, 04:49 PM
I have a thousand text (*.TXT) files in my "C:\My Report" folder and I want to extract the TITLE values from each one of them and paste them to Excel. My problem is the way these text files are formatted. There are a lot of hard/carriage returns. See attached sample below:

[IPC]
B22C-5/00
[TITLE]
Casting waste sand regeneration roasting
processor
???????????
[ABSTRACT]

Output in Excel file:
Casting waste sand regeneration roasting processor

Anyone with ideas?

SamT
05-03-2013, 06:38 PM
Which of these statements are true/False?

All Titles are proceeded by the line "[TITLE]"
All Titles are on two lines
The line "[ABSTRACT]" is always preceeded by one line after the title.

swaggerbox
05-03-2013, 07:17 PM
Which of these statements are true/False?

All Titles are proceeded by the line "[TITLE]"
All Titles are on two lines
The line "[ABSTRACT]" is always preceeded by one line after the title.

Hi Sam, thanks for the reply.

All Titles are proceeded by the line "[TITLE]" >> TRUE
All Titles are on two lines >> FALSE (it is variable)
The line "[ABSTRACT]" is always preceeded by one line after the title >> TRUE

SamT
05-04-2013, 07:45 AM
All titles are on one to max lines.

What is max?

snb
05-04-2013, 12:16 PM
sub M_snb()
with createobject("scripting.filesystemobject")
for each it in split(createobject("wscript.shell").exec("cmd /c Dir ""C:\my folder\*.txt"" /b").stdout.readall,vbcrlf)
c00=c00 & vblf & replace(split(split(.opentextfile(it).readall,"[ABSTRACT]")(0),"[TITLE]")(1),vbcrlf," ")
next
end with

sn=split(c00,"|")
thisworkbook.sheets(1).cells(1).resize(ubound(sn)+1)=application.transpose( sn)
End Sub