I have the following code I am trying to run in a shared Addin which is stored on a Corporate One Drive in a Shared file.
When someone is using the addin it's suppose to create a log showing who has the addin locked up in case you want to update the code.
My Addin is saved with a .xlam extension and is not marked as read only under properties.
Here is a link to the posting showing what the code is suppose to do and how to deploy it.
Find out who has Excel file locked for editing - wellsr.com
I keep getting a error 91 on the line of code I am showing below.
Can someone please explain to me why I getting this error and how to possibly fix it.
Thanks in Advance.
When someone is using the addin it's suppose to create a log showing who has the addin locked up in case you want to update the code.
My Addin is saved with a .xlam extension and is not marked as read only under properties.
Here is a link to the posting showing what the code is suppose to do and how to deploy it.
Find out who has Excel file locked for editing - wellsr.com
I keep getting a error 91 on the line of code I am showing below.
Can someone please explain to me why I getting this error and how to possibly fix it.
Thanks in Advance.
VBA Code:
'Place these macros in your "ThisWorkbook" object
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next ' ignore possible errors
If Not ActiveWorkbook.ReadOnly = True Then
'only try to delete the file if the user has it locked
Kill ThisWorkBook.Path & "\usage.log" ' delete the file if it exists and it is possible
End If
On Error GoTo 0 ' break on errors
End Sub
Private Sub Workbook_Open()
Dim file1 As Integer
Dim strLine As String
file1 = FreeFile
If Not ActiveWorkbook.ReadOnly = True Then
'only add name to the usage log if the user has it locked
Open ThisWorkBook.Path & "\usage.log" For Append As #file1
Print #file1, Environ("USERNAME") & " at " & Now()
Close #file1
Else
'if someone else has the file open, find out who
Open ThisWorkBook.Path & "\usage.log" For Input Access Read As #file1
Do While Not EOF(file1)
Line Input #file1, strLine
Loop
Close #file1
MsgBox "The file was locked by following user: " & strLine 'last line of file"
End If
End Sub