Identify computer Login ID

S

SJW_OST

I am looking for a way to have Excel identify and record the ID used to log
onto the computer as a way of identifying who has accessed/opened the Excel
file. So if I open the Excel file, I want the workbook to record my computer
Login ID on a sheet in cell A1. Then if my coworker opens the file I want
their ID to be recorded under mine in cell A2, the next coworker in cell A3
and so forth.
I found a way to do this operation in Access but now I need the same thing
in Excel.

Any help is greatly appreciated!
Stephen W
 
B

Barb Reinhardt

Try this

Sub test()
Dim myUserName As String
Dim objNetwork As Object
Set objNetwork = CreateObject("Wscript.network")
myUserName = objNetwork.UserName
Debug.Print myUserName
End Sub

There may be another way, but it works
 
S

SJW_OST

Your code works great.
I found this code that works as well.

Sub CaptureUserID()
'2 cells must be filled in for this. Enter a character in cell A1 & A2.

Dim rng As Range

Set rng = Sheets("Sheet3").Range("A1").End(xlDown).Offset(1, 0)

rng.Value = Now()
rng.Offset(0, 1) = Application.UserName
ActiveWorkbook.Save
End Sub

Thanks for all of your help!
Stephen W
 
G

Gord Dibben

Application.Username is just the name typed into

Tools>Options>General>Username

Environ("Username") is the login name.


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top