Can you try to add the below function in a VBE module:
Code:
Function IsFileLocked(filePath As String) As Boolean
On Error Resume Next
Open filePath For Binary Access Read Write Lock Read Write As #1
Close #1
If Err.Number <> 0 Then
IsFileLocked = True
Application.StatusBar = "Waiting for file to close"
Err.Clear
Else
IsFileLocked = False
Application.StatusBar = ""
End If
End Function
And after that you should also add the below in the workbook module:
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim fName As String
fName = "your file name" 'file name goes here
If IsFileLocked(fName) Then
MsgBox ("File is locked" & vbCrLf & "Please try again later")
Cancel = True
End If
End Sub
Bookmarks