PDA

View Full Version : Solved: how do i get the the name of the user who opened the file?



mancubus
02-02-2011, 07:58 AM
hi board.

i tried the codes by Ivan Moala at
http://www.xtremevbtalk.com/showthread.php?t=160978&page=2&pp=20
but user name returned null. (no errors, just blank MsgBox.)

and below returned my username, not the person's name who opened the file.

Msgbox(ActiveWorkbook.WriteReservedBy)


any ideas?

Jan Karel Pieterse
02-02-2011, 08:18 AM
So far the most reliable way I've seen is:
- check if workbook is opened in read/write mode
- If so, update a (custom) document property with the username
- Save the file.
If a user opens read-only, read the property to extract the name of the user working on the file.

gnod
02-02-2011, 08:20 AM
hi board.

i tried the codes by Ivan Moala at
http://www.xtremevbtalk.com/showthread.php?t=160978&page=2&pp=20
but user name returned null. (no errors, just blank MsgBox.)

and below returned my username, not the person's name who opened the file.

Msgbox(ActiveWorkbook.WriteReservedBy)

any ideas?
hi, the user name will be coming from Tools -> Options -> General Tab
under username field, if it blank it will use the computer name instead

mancubus
02-02-2011, 09:31 AM
thanks for the replies.

for clarification i must add related bit of my code...


Sub DosyaAcUpdateKapa()
Dim wb As Workbook
Set wb = Workbooks.Open("C:\test.xls")
If wb.ReadOnly Then
MsgBox wb.Name & " is Read-Only!"
MsgBox wb.WriteReservedBy
wb.Close Savechanges:=False
End If
'code
'code
End Sub



if the file is opened by another user and if i want to open dile file directly from its folder by double-clicking or file-open, i get File in Use warning.

test.xls is locked for editing

by 'name_of_user'

Open 'Read-Only' or, click 'Notify' to...


what i want is to get the 'name_of_user' string displayed in File in Use msg via VBA.

Jan: the file is for data entry and is not opened as Read-Only by users.
gnod: yes i get my user name as i defined in user name field of options-general.



so i understand, i can't get it by wb.WriteReservedBy

mancubus
02-02-2011, 11:01 AM
ok.

i will try the GetLastUser sub by Brian Baulsom at

http://www.mrexcel.com/forum/showthread.php?p=2367992

with IsFileOPen function.

thanks....