This works perfectly well and does what I want but in the 3rd last line of the piece of code shown below where I have “File OutPut:” I would like to have the actual name of the file instead. I have tried every which way to achieve this but without success. Although I think it is to do with “Object Required” I’m not sure how to resolve it.
I would be grateful if someone could point me in the right direction.
Thank you
[code]
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set folder = objFSO.GetFolder(strFilePath)
for each file in folder.Files
Set objfile = objFSO.OpenTextFile(file.path, ForReading)
strContents = objfile.readAll
‘Load String Into Array
outputArray = split(strContents,”.”)
‘Check For KeyWord Match
for each strCurrentLine in outputArray
If InStr(strCurrentLine, strKeyWord) Then
‘Concatenate Matches
strOutput = strOutput & “File OutPut: ” & vbCRLF & strCurrentLine & “.” & vbCRLF & vbCRLF
End if
next
[/code]
I think you just need file.name:
strOutput = strOutput & “File OutPut: ” & file.name & vbCRLF & strCurrentLine & “.” & vbCRLF & vbCRLF
I assume there’s another “next” to close the “for each file” loop, since your program’s working.
I think your var. names kind of confused things, what with two different objects having related names (file, and objfile). “file” is an object, subordinate to folder, and so is “objfile”, subordinate to fso.