Insert user ID

Dave_cha

Registered User.
Local time
Today, 21:12
Joined
Nov 11, 2002
Messages
119
Does anyone know if and how I can insert the pc logon ID into an excel cell each time the user opens the excel file?

Various users will have access to the file so the current user's details will have to replace that of the previous user.

Thanks,

Dave
 
Something like this works:
Code:
Private Sub Workbook_Open()
    Worksheets("sheet").Range("a1").Value = Environ("username")
End Sub

Does the name have to be saved when no changes are made? If so you need to save the file after updating the field.

If macro security is set to medium or high a user can disable macro's and the value won't be set.

Excel stores the last one who saved the file in the extended file properties, you can access them from VBA by:
Code:
ActiveWorkbook.BuiltinDocumentProperties.Item("Last author")
 
Thanks Peter, that worked perfectly.

I don't suppose you've ever connected to a MySQL db from Excel? :)
Would be nice to lookup the employee name from the ID.

Dave
 
Hi Peter, Excel help tells you to use Application.UserName
but I have used Environ("username") in Access, I tried both plus your example to retrieve previous author and got interesting results. I would add that this is a home pc not on a network but don't see what difference it would make

The code
Code:
Private Sub Workbook_Open()
    Worksheets("sheet1").range("a2").Value = Environ("username")

Worksheets("sheet1").range("a1").Value = Application.UserName

 Worksheets("sheet1").range("a3").Value = ActiveWorkbook.BuiltinDocumentProperties.Item("Last author")
End Sub

The 2nd and 3rd returned WARNOCK the Licensee of Excel the 1st returned US Lot which is how we sign on and what was expected.
Any explanations for a curious guy ?

Brian
 

Users who are viewing this thread

Back
Top Bottom