I've searched and used various codes that I can find on the net, but they don't seem to work. I basically want to check if a file is open. Does anyone have a function that works?
I've searched and used various codes that I can find on the net, but they don't seem to work. I basically want to check if a file is open. Does anyone have a function that works?
Thanks, Orange, but regardless which function I've used, I keep getting ErrNum of 53 whether a file is open or not. Therefore, it's always considered open.
Code:Select Case ErrNum Case 0 '''''''''''''''''''''''''''''''''''''''''''' ' No error occurred. ' File is NOT already open by another user. '''''''''''''''''''''''''''''''''''''''''''' IsFileOpen = False Case 70 '''''''''''''''''''''''''''''''''''''''''''' ' Error number for "Permission Denied." ' File is already opened by another user. '''''''''''''''''''''''''''''''''''''''''''' IsFileOpen = True Case Else '''''''''''''''''''''''''''''''''''''''''''' ' Another error occurred. Assume open. '''''''''''''''''''''''''''''''''''''''''''' IsFileOpen = True End Select
for all those wondering what error 53 is - its 'file not found'.
I've not tested Chip's code but chances are you have missed something in the code you haven't shown.
I just tested it (Chip Pearson function) and it gives me False repeatedly, but I have the file open in Notepad???
I also checked with a modified version of that code from
http://www.utteraccess.com/forum/Che...&hl=isfileopen
and it also showed False???
I also checked another version and its test routine from
https://exceloffthegrid.com/vba-find-file-already-open/
and it did not work either.
When my test file "zeeTrans.txt" was open, all these functions reported IsOpenFile as False???
One factor I did note was that each of these functions (in vba) came from Excel-oriented sites.
If someone gets any of these functions to work, please show us the code and the test routine to call the function.
UPDATE:
I found info at https://stackoverflow.com/questions/...open-by-anyone
where poster could not get this function to work. He, like me, was using a txt file.
Another update:
Just got an email and within I found this
I opened a jpg, then a png with Irfanview -- in both cases the function said File was not Open.(I do want to note that if you use Notepad to open up a file, it will not actually lock the file even though you can clearly see it being used. For some reason, Notepad will open the file and keep it in memory and then only claim a lock on it long enough to save the updates.)
However, I did open a word file (.docx) and the function told me it was already open.