Runtime Error 53: File nOt found

skunumber

New Member
Joined
Apr 14, 2011
Messages
2
Hi folks,

My first post here. Here is my problem. I am using Excel VB to open a text file and extract information from it. Here is my code.

Private Sub Parse_EventLogs(EventLogDir As String)
Dim File As String ' File handle for the eventlog file
Dim FCount As Long ' Total number of eventlog files processed
Dim Processedcount As Long ' Total number of eventlog files processed
Dim fn As Integer ' File number
Dim thisline As String

FCount = 0
File = Dir(EventLogDir)
'find out total numberof eventlogs in the directory
Do While Len(File) > 0
FCount = FCount + 1
File = Dir
Loop

File = Dir(EventLogDir)
Processedcount = 0
Do While Len(File) > 0
Processedcount = Processedcount + 1
LogInfo " Processing file " & Processedcount & " of " & FCount
fn = FreeFile()
Open File For Input As #fn
Do While Not EOF(fn)
Line Input #fn, thisline

'Extract Data

Loop

File = Dir
Loop

End Sub

The code goes to the directory and gives an a correct count of how mnay files are in the directory. The variable 'File' has a valid filename all the way through. But when it goes to execute the 'Open' statement, it says runtime error 53 File not found. I don't understand. The file exists, the file name is valid but it cannot open it. I changed the attribute on the entire folder and still the same error. I have another function writing a log file and that seems to open the file no problem.

Please help. Thanks.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top