[Solved] Macro to check if a file is open or locked
Posted: Mon Jan 17, 2011 4:12 pm
I'm looking for a code to check if a OOo Calc or OOo Writer File is open.
In VBA I used the function below:
If the file was open by another user, the FileLocked Function returned True.
But it doesn't work for Ooo Files.
Can anyone help me?
In VBA I used the function below:
Code: Select all
Function FileLocked(strFileName As String) As Boolean
On Error Resume Next
' If the file is already opened by another process,
' and the specified type of access is not allowed,
' the Open operation fails and an error occurs.
Open strFileName For Binary Access Read Write Lock Read Write As #1
Close #1
' If an error occurs, the document is currently open.
If Err.Number <> 0 Then
' Display the error number and description.
FileLocked = True
Err.Clear
End If
End Function
But it doesn't work for Ooo Files.
Can anyone help me?