Macros to show user name when opening locekd Excel file

TK2

New Member
Joined
Dec 17, 2009
Messages
3
Hi.

My Excel file is located on network drive and I have a macros which automatically exports data from outlook message to excel file.

In case some other user has opened this file I can not run a macros, because file is read only.

excel_multiple.jpg


There is a KB article "Macro code to check whether a file is already open".
http://support.microsoft.com/kb/291295

My question is:
"How to show username of person who have locked the file?"

E.g.

If IsFileOpen("c:\Book2.xls") Then
' Display a message stating the file in use.
MsgBox "File already in use by: " + username
'
' Add code here to handle case where file is open by another
' user.
'
End if
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi TK2

If you dont want at another people can open it, give the file password.

If You want at they can open it, share the file. Tools, shareworkbook.

Then you can use it normaly. And you can see later how have change it

-Joxu
 
Upvote 0
Not tested but perhaps another way (From Help). Paste below in the Thisworkbook Code Sheet

Code:
Private Sub Workbook_Open()
With ActiveWorkbook
    If .WriteReserved = True Then
        MsgBox "This file is not Shareable - Please contact " & .WriteReservedBy & Chr(13) & _
            " if you need to insert data in this workbook."
    Me.Close SaveChanges:=False
    End If
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,847
Members
452,361
Latest member
d3ad3y3

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