sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,422
- Office Version
- 2016
- Platform
- Windows
I'm trying to loop through a folder full of txt files and extract the information from within but I'm getting an error 53, file not found, and I don't know why.
This is what I have so far:
the code fails on this line:
Can anyone advise why this won't work please?
This is what I have so far:
VBA Code:
directory = "\\Saved Folder\Data Files\To be imported\"
FileName = Dir(directory & "\*Data*.txt")
Do While FileName <> ""
FileName = Left(FileName, Len(FileName) - 4)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(FileName, ForReading)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.ReadLine
MsgBox strComputer
Loop
the code fails on this line:
VBA Code:
Set objTextFile = objFSO.OpenTextFile(FileName, ForReading)
Can anyone advise why this won't work please?