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.



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
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Joxu

New Member
Joined
Nov 19, 2009
Messages
21
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
 

Sandeep Warrier

Board Regularmmmm Pizza
Joined
Oct 31, 2008
Messages
2,672
Hi

See if this helps.
<input id="gwProxy" type="hidden"><!--Session data--><input *******="jsCall();" id="jsProxy" type="hidden">
 

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,475
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
 

Watch MrExcel Video

Forum statistics

Threads
1,118,563
Messages
5,572,936
Members
412,490
Latest member
hrzagi
Top