Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Search text of external files and import

I have about 80 text files (.txt) that contain results of PC vulnerability
scans. Each file represents a different machine, and each file contains
multiple "Passed" and/or "Failed" results depending on what vulnerabilities
are present. All files are in a common networked folder - separate from the
Excel spreadsheet.
I wish to query each file for any instances of "=Failed" and output the
preceeding 12 alphanumeric characters into a cell. "=Passed" can be ignored.

For instance, if "testcase1.txt" contains the following data:
2005_292_004=Failed
2005_292_005=Failed
2005_315_001=Passed

Then the reference cell should return "2005_292_004, 2005_292_005"; if all
were "Passed" then the cell can read "none".

So if multiple files were queried, the xls may look like below (the '|'
indicates separate columns:
testcase1.txt | 2005_292_004, 2005_292_005
testcase2.txt | None
testcase3.txt | 2005_292_004
testcase4.txt | 2005_315_005
testcase5.txt | None


Thank you for any help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Search text of external files and import

Sorry I can't help you then..

You will be able to do it, but it's going to take you a fair amount of
coding..

Think of excel and access as different tools.. Access is used for data
gathering and maniuplation. Excel is use for analysis and reporting.

if I can use a tool analogy, you can drive a screw into a wall with a
hammer, but it's not the right tool.. In the end it will work, but it's not
going to be a pleasant experience...



"flaterp" wrote:

I am not familiar with Access and other data is within the existing
spreadsheet, so I would like to use it.


"TomHinkle" wrote:

if you use access, and link the txt files, should take you about 5 minutes to
write the queries..

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Search text of external files and import

Sub ReadStraightTextFile()
Dim sStr as String
Dim LineofText As String
Dim fName as String
dim i as Long
fname = dir("C:\Myfiles\*.txt)
i = 0
Redim list(1 to 1)
do while fname<""
i = i + 1
if i < 1 then
Redim Preserve list(1 to i)
end if
List(i) = fname
fName = dir()
Loop
Open "C:\Results.txt" For Output As #2

for i = 1 to ubound(list)
Open "C:\MyFiles\" & List(i) For Input As #1
sStr = ""
Do While Not EOF(1)
Line Input #1, LineofText
if(instr(1,LineofText,"=Failed",vbTextCompare) then
sStr = sStr & Left(LineofText,12) & ", "
End if
Loop
if len(str) = "" then
Print #2, List(i) & " | None"
else
Print #2, List(i) & " | " & Left(sStr,len(sStr)-2)
end if
'Close the file
Close #1
Next
Close #2
End Sub

Code is untested and may contain typos, but should get you started.

--
Regards,
Tom Ogilvy


"flaterp" wrote in message
...
I have about 80 text files (.txt) that contain results of PC vulnerability
scans. Each file represents a different machine, and each file contains
multiple "Passed" and/or "Failed" results depending on what

vulnerabilities
are present. All files are in a common networked folder - separate from

the
Excel spreadsheet.
I wish to query each file for any instances of "=Failed" and output the
preceeding 12 alphanumeric characters into a cell. "=Passed" can be

ignored.

For instance, if "testcase1.txt" contains the following data:
2005_292_004=Failed
2005_292_005=Failed
2005_315_001=Passed

Then the reference cell should return "2005_292_004, 2005_292_005"; if all
were "Passed" then the cell can read "none".

So if multiple files were queried, the xls may look like below (the '|'
indicates separate columns:
testcase1.txt | 2005_292_004, 2005_292_005
testcase2.txt | None
testcase3.txt | 2005_292_004
testcase4.txt | 2005_315_005
testcase5.txt | None


Thank you for any help.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Search text of external files and import

Thank you very much, Tom. I made some adjustments to accomodate the desired
output, and the code works well.


"Tom Ogilvy" wrote:

Sub ReadStraightTextFile()
Dim sStr as String
Dim LineofText As String
Dim fName as String
dim i as Long
fname = dir("C:\Myfiles\*.txt)
i = 0
Redim list(1 to 1)
do while fname<""
i = i + 1
if i < 1 then
Redim Preserve list(1 to i)
end if
List(i) = fname
fName = dir()
Loop
Open "C:\Results.txt" For Output As #2

for i = 1 to ubound(list)
Open "C:\MyFiles\" & List(i) For Input As #1
sStr = ""
Do While Not EOF(1)
Line Input #1, LineofText
if(instr(1,LineofText,"=Failed",vbTextCompare) then
sStr = sStr & Left(LineofText,12) & ", "
End if
Loop
if len(str) = "" then
Print #2, List(i) & " | None"
else
Print #2, List(i) & " | " & Left(sStr,len(sStr)-2)
end if
'Close the file
Close #1
Next
Close #2
End Sub

Code is untested and may contain typos, but should get you started.

--
Regards,
Tom Ogilvy


"flaterp" wrote in message
...
I have about 80 text files (.txt) that contain results of PC vulnerability
scans. Each file represents a different machine, and each file contains
multiple "Passed" and/or "Failed" results depending on what

vulnerabilities
are present. All files are in a common networked folder - separate from

the
Excel spreadsheet.
I wish to query each file for any instances of "=Failed" and output the
preceeding 12 alphanumeric characters into a cell. "=Passed" can be

ignored.

For instance, if "testcase1.txt" contains the following data:
2005_292_004=Failed
2005_292_005=Failed
2005_315_001=Passed

Then the reference cell should return "2005_292_004, 2005_292_005"; if all
were "Passed" then the cell can read "none".

So if multiple files were queried, the xls may look like below (the '|'
indicates separate columns:
testcase1.txt | 2005_292_004, 2005_292_005
testcase2.txt | None
testcase3.txt | 2005_292_004
testcase4.txt | 2005_315_005
testcase5.txt | None


Thank you for any help.




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
Import text files into EXCEL Annette Excel Discussion (Misc queries) 1 March 1st 09 10:16 PM
import a many text files to excel programmatically sherry Excel Discussion (Misc queries) 16 September 25th 07 10:26 PM
Import External Text Data and Refreshing Problem Douglas Excel Worksheet Functions 0 August 20th 07 09:30 AM
Search text of external files and import TomHinkle Excel Programming 1 November 18th 05 04:20 PM
How can you import external text file paragraph a into single cell Sam Excel Discussion (Misc queries) 0 April 14th 05 12:58 PM


All times are GMT +1. The time now is 10:24 AM.

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

About Us

"It's about Microsoft Excel"