RichardMGreen
Well-known Member
- Joined
- Feb 20, 2006
- Messages
- 2,177
Hi all
I'm using the following code :-
to check if a file is open before allowing a macro to run.
The file in question has a warning about being opened read-only when you open it normally which looks to be making the code fail even when no-one else has the file open.
Anyone any idea on how to bypass this?
I can't change the warning as it's needed by other people.
I'm using the following code :-
Code:
Function IsFileOpen(file_to_open As String) As Boolean
Dim hdlFile As Long
On Error GoTo FileIsOpen:
hdlFile = FreeFile
Open strFileToOpen For Random Access Read Write Lock Read Write As hdlFile
IsFileOpen = False
Close hdlFile
Exit Function
FileIsOpen:
IsFileOpen = True
Close hdlFile
End Function
to check if a file is open before allowing a macro to run.
The file in question has a warning about being opened read-only when you open it normally which looks to be making the code fail even when no-one else has the file open.
Anyone any idea on how to bypass this?
I can't change the warning as it's needed by other people.