If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Getting username of a locked file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-12-04, 12:11
orionrafal orionrafal is offline
Registered User
 
Join Date: Feb 2004
Posts: 4
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
Reply With Quote
  #2 (permalink)  
Old 02-12-04, 14:11
Smitty Smitty is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 02-16-04, 20:26
Xl-Dennis Xl-Dennis is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On