Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    4

    Unanswered: Getting username of a locked file

    How can I get the username of an opened file in VBA, but not the one in Application.UserName

  2. #2
    Join Date
    Dec 2003
    Location
    San Diego, CA
    Posts
    153
    Welcome to the Board!

    Would this example help?
    Code:
    Sub MyName()
        Dim CurrentUserName As String
            CurrentUserName = Environ("Username")
        MsgBox CurrentUserName
    End Sub
    Smitty

  3. #3
    Join Date
    Dec 2003
    Location
    Östersund Sweden
    Posts
    60
    Hi guys,

    It may be needed with another approach if the client is part of a network. Following examples gives the username & time:

    Code:
    Declare Function GetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" _
    (ByVal lpBuffer As String, nSize As Long) As Long
    
    Function UserName() As String
    Dim Buffer As String * 100
    Dim BuffLen As Long
    BuffLen = 100
    GetUserName Buffer, BuffLen
    UserName = Left(Buffer, BuffLen - 1)
    End Function
    
    Private Sub Workbook_BeforeSave _
    (ByVal SaveAsUI As Boolean, Cancel As Boolean)
    With ActiveSheets
           .Range("a1") = UserName()
           .Range("B1") = Now
    End With
    End Sub
    Kind regards,
    Dennis
    Kind regards,
    Dennis

Posting Permissions

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