tempate question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a template (on a network location) that many people use. When the
template is used to create a new file on a machine, I'd like the user's name
information to automatically be inserted into one of the spreadsheet cells.
I figure that the template will need a macro that runs on creation. How
might I do this, please?
 
Give this a try

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel A
Boolean)

Sheets("Sheet1").Name = Environ("username")

End Sub

Just replace Sheet1 with the name of the sheet you wish to be re-name
 
Peter81's reply changes the name of the sheet (the 'tab'). If you want
to enter the user name in a specific cell, use this code:


Private Sub Workbook_Open()
Range("L3").Select 'edit this range to desired location of username

ActiveCell.FormulaR1C1 = Environ("username")
Range("A1").Select ' use this line to position cell pointer to
desired starting point
End Sub


Good Luck
 
Thanks for the response, Peter. However, I don't think I was clear on my
desire (or I didn't understand your answer - perhaps I need a refresher on
macros in excel). What would be ideal is that the user name show up in cell
B2 when a new document is created based on the specific template I am
creating. I figure the code to do this must be stored with the template. If
what you posted should work (although I don't think the event is correct or
even that the event I want is available), could you please give me a bit more
info on how to use it?

Thanks,
Peter
 
Thanks swatspOp. That got me much closer. It seems the Environ() function
deals with system information. How might I go about assigning name,
initials, etc., that are associated with Office?

Peter
 
Back
Top