samkeenan3
New Member
- Joined
- Mar 15, 2021
- Messages
- 4
- Office Version
- 2016
- Platform
- Windows
Running in Excel 2016 on Win10:
I've been testing a workbook that will be used by several users to write data to a single workbook stored on a network. I am using a VBA function to checks that the network file is not already open before opening it, writing data in it, and saving and closing it.
The function is as follows and comes from this thread: VBA How to report which User has File Open?
Function IsFileOpen(strFullPathFileName As String) As Boolean
Dim hdlFile As Long
On Error GoTo FileIsOpen:
hdlFile = FreeFile
Open strFullPathFileName For Random Access Read Write Lock Read Write As hdlFile
IsFileOpen = False
Close hdlFile
Exit Function
FileIsOpen:
IsFileOpen = True
Close hdlFile
End Function
When I run the function the first time and the workbook is not open, it works fine. However, on each subsequent time it will always return True (i.e workbook is open) - even when the workbook is verifiably not open.
Have I missed something obvious?
I've been testing a workbook that will be used by several users to write data to a single workbook stored on a network. I am using a VBA function to checks that the network file is not already open before opening it, writing data in it, and saving and closing it.
The function is as follows and comes from this thread: VBA How to report which User has File Open?
Function IsFileOpen(strFullPathFileName As String) As Boolean
Dim hdlFile As Long
On Error GoTo FileIsOpen:
hdlFile = FreeFile
Open strFullPathFileName For Random Access Read Write Lock Read Write As hdlFile
IsFileOpen = False
Close hdlFile
Exit Function
FileIsOpen:
IsFileOpen = True
Close hdlFile
End Function
When I run the function the first time and the workbook is not open, it works fine. However, on each subsequent time it will always return True (i.e workbook is open) - even when the workbook is verifiably not open.
Have I missed something obvious?