+ Reply to Thread
Results 1 to 5 of 5

tempate question

  1. #1
    Peter
    Guest

    tempate question

    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?

  2. #2
    Registered User
    Join Date
    07-19-2005
    Posts
    13

    Give this a try

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

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

    End Sub

    Just replace Sheet1 with the name of the sheet you wish to be re-named

  3. #3
    Forum Expert swatsp0p's Avatar
    Join Date
    10-07-2004
    Location
    Kentucky, USA
    MS-Off Ver
    Excel 2010
    Posts
    1,545
    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:

    [vba]
    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
    [/vba]

    Good Luck
    Bruce
    The older I get, the better I used to be.
    USA

  4. #4
    Peter
    Guest

    Re: tempate question

    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

    "Peter81" wrote:

    >
    > Give this a try
    >
    > Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
    > Boolean)
    >
    > Sheets("Sheet1").Name = Environ("username")
    >
    > End Sub
    >
    > Just replace Sheet1 with the name of the sheet you wish to be re-named
    >
    >
    > --
    > Peter81
    > ------------------------------------------------------------------------
    > Peter81's Profile: http://www.excelforum.com/member.php...o&userid=25353
    > View this thread: http://www.excelforum.com/showthread...hreadid=474123
    >
    >


  5. #5
    Peter
    Guest

    Re: tempate question

    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

    "swatsp0p" wrote:

    >
    > 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
    >
    >
    > --
    > swatsp0p
    >
    >
    > ------------------------------------------------------------------------
    > swatsp0p's Profile: http://www.excelforum.com/member.php...o&userid=15101
    > View this thread: http://www.excelforum.com/showthread...hreadid=474123
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1