Run Time Error "91"

mayoung

Active Member
Joined
Mar 26, 2014
Messages
259
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
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.

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


1659537208974.png



1659537180279.png
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top