PC User Name and date in cells

A

ArcticWolf

Hi,

When the user opens the file for the first time - I need Excel to input the
User name of the PC in A1, and in B1 I need to put todays date. When I open
the file tomorrow I still need it to show "yesterdays" date - so is there
away I can keep it static?

Thanks in advance,

AW
 
S

Shane Devenshire

You will need a VBA macro here is a quick sample:

Here is some sample code for the Workbook_Open procedure:

Private Sub Workbook_Open()
myInfo = InputBox("Enter your ID")
If myInfo <> "" Then
'your code
End If
End Sub

This code goes into the thisWorkbook object in the VBE. Press Alt+F11,
double-click the thisWorkbook object, for your workbook, in the Project
explorer near the top left of the screen.
 
P

Paul C

As an alternate to an InputBox you could use Application.UserName, but you
need to make sure that the individuals have entered thier user name in the
Excel
Tools:Options:General area.

Private Sub Workbook_Open()
If Sheets("SheetName").range("A1") = Empty then
Sheets("SheetName").range=("A1")=Application.UserName
Sheets("SheetName").range=("B1")=Date
End if

End Sub
 
G

Gord Dibben

You may want to get the user's login name rather than Application username,
which could be anything or nothing.

Environ("UserName")


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