Consulting

Results 1 to 5 of 5

Thread: Solved: how do i get the the name of the user who opened the file?

  1. #1
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644

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

    hi board.

    i tried the codes by Ivan Moala at
    http://www.xtremevbtalk.com/showthre...8&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.

    [VBA]Msgbox(ActiveWorkbook.WriteReservedBy)[/VBA]


    any ideas?
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  2. #2
    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.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    VBAX Tutor gnod's Avatar
    Joined
    Apr 2006
    Posts
    257
    Location
    Quote Originally Posted by mancubus
    hi board.

    i tried the codes by Ivan Moala at
    http://www.xtremevbtalk.com/showthre...8&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.

    [vba]Msgbox(ActiveWorkbook.WriteReservedBy)[/vba]

    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

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    thanks for the replies.

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

    [vba]
    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
    [/vba]


    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
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    ok.

    i will try the GetLastUser sub by Brian Baulsom at

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

    with IsFileOPen function.

    thanks....
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •