Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Capture users ID when they open a spreadsheet

  Asked By: Pedro    Date: Dec 31    Category: MS Office    Views: 642
  

I have a spreadsheet that may be used by anyone of up to 12 people.
They will use it to update entries already there, adn what I want to
do is somehow get their login id, and autopopulate a cell in the
spreadsheet with either their ID or their name.

Is this possible?

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Julia Hughes     Answered On: Dec 31

How is the ID entered????????????????????????

 
Answer #2    Answered By: Scarlett Hughes     Answered On: Dec 31

Worksheets("Log").Range("A1").End(xlDown).Offset(1,0).Value =
Environ("Username")

 
Answer #3    Answered By: Marina Smith     Answered On: Dec 31

See if this gets you what you need: paste the following new function into a VB
module:

Option Explicit
'api call for obtaining the username
Private Declare Function GetUserName& Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long)

Public Function WindowsUserName() As String
Dim szBuffer As String * 100
Dim lBufferLen As Long
lBufferLen = 100
If CBool(GetUserName(szBuffer, lBufferLen)) Then
WindowsUserName = Left$(szBuffer, lBufferLen - 1)
Else
WindowsUserName = CStr(Empty)
End If
End Function


The above new function returns the username by entering the new function into a
cell:
say cell  B2=WindowsUserName( )
I found this cool one at vbaexpress.com

 
Answer #4    Answered By: Verner Fischer     Answered On: Dec 31

Here is a modify version of some code I use to check for a qualified
user.

Sub ConfirmUser()
Dim bolUser As Boolean

bolUser = CheckUser(Environ("USERNAME"))

If bolUser = True Then
If Application.UserName <> "" Then
Range("B1") = Application.UserName
Else
Range("B1") = Environ("USERNAME")
End If
End If

End Sub

Function CheckUser(strUser As String) As Boolean
Dim arrTeam(0 To 8) As String
Dim intCount As Integer

arrTeam(0) = "user1"
arrTeam(1) = "user2"
arrTeam(2) = "user3"
arrTeam(3) = "user4"
arrTeam(4) = "user5"
arrTeam(5) = "user6"
arrTeam(6) = "user7"
arrTeam(7) = "user8"
arrTeam(8) = "user9"


On Error GoTo NoUser:
For intCount = 0 To UBound(arrTeam)
If strUser = arrTeam(intCount) Then
CheckUser = True
Exit For
End If
Next intCount
Exit Function
NoUser:
CheckUser = False
End Function

 
Didn't find what you were looking for? Find more on Capture users ID when they open a spreadsheet Or get search suggestion and latest updates.




Tagged: