Error 55 File Already Open

M

Mike H.

Why would I get a "false" error 55, file already open when doing this:

Open ThisWorkbook.Path & "\logdtls.log" For Append As #1

I am careful to always issue this:
Close #1
I am calling this code over and over as the subs progreses so I can write a
lot file of activities.
But I am getting this error quite a bit. Ideas?
Even if I hard-code the path to "c:\temp" or whatever, I still get the error.
 
J

Joel

Do you have any On Error Statments. The On Error statemenmts may be
bypasssing the close statements. I don't use On Error because it masks real
errors that need to be fixed. If I do I make sure I also have On Error GoTo
0.

I would add a msgbox() in you On Error statements so you know when errors
are occuring.
 
M

Mike H.

I have a whole separate section on each sub for error handling and I am going
to that error-handling section each time I call the sub for opening the file.
I always use freefile() without a parameter to get the next available file #
to open as I may have a file open when I issue this log routine. FreeFile()
seems to work across multiple subs so I don't see a problem there, but I am
getting the error none the less.
 
J

Joel

Shouldn't you be doing this?
filenumber = freefile()
Open ThisWorkbook.Path & "\logdtls.log" For Append As filenumber

You had a hard codes #1 in your example you posted.
 
M

Mike H.

I think I figured it out. I had some sloppy code and had stopped the code
when the file was still open for append. I killed the sub but did not ever
close excel so it kept the file open. So I had to exit excel before the
error was gone. I did get the code all cleaned up. Don't ever assume you
can use file #1 and always use FreeFile()!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top