update user name in excel on open

F

fishy

We have a standard build on our PC's that returns a generic user on excel if
people havent updated their User Name details in the 'Tools', 'Options',
'General' tab.

I want to be able to capture the users NT logon and write this to the user
name field in excel so that it stores this permanantly whenever they open
this workbook.

I have tried to google etc but cant see anything that updates this field but
loads that store the username in the book.
 
J

Jacob Skaria

From workbook press Alt+F11 to launch VBE (Visual Basic Editor). From the
left treeview search for the workbook name and click on + to expand it.
Within that you should see the following

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
This Workbook

Double click 'This WorkBook' and paste the below code to the right code pane.

Private Sub Workbook_Open()
Application.UserName = Environ("Username")
End Sub
 

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