Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    Chatham, Ontario, Canada
    Posts
    86
    Thanks
    5
    Thanked 1 Time in 1 Post

    insert field (97/2000)

    Is there a method to insert a document field, specifically UserName and a custom field, into a cell?
    Failing that is there an OnOpen trigger that can be accessed in VBA.

    Having been accustomed to using both in Word I was unpleasantly surprised when I could find neither in Excel. I hope that I'm just looking in the wrong place.

  2. #2
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: insert field (97/2000)

    In excel, custom fields are generally replaced with a formula, (or VBA programming). If you can be more specific as to what you want to do, I'm sure someone in this lounge can assist you with either.
    As for an OnOpen trigger, you can generate any macro and save it with the name AUTO_OPEN. This will trigger automatically when you open the file!
    (The other method is to attach the code to a "OnOpen" workbook event.
    Regards,
    Rudi

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: insert field (97/2000)

    It looks like you'll need a User Defined Function (a custom built worksheet function) for this:

    Public Function UserName() As String
    UserName = Application.UserName
    End Function

    To use it in a cell, you also need to specify the workbook that contains the Function, like this:

    =PERSONAL.XLS!username()

    UDF's must reside in a module. The UDF will change the Username to whoever opens the Workbook.

    Edit: I overlooked the second part of your question. To stamp a username into a cell, use the Workbook_Open() Event you will find under the ThisWorkbook Module, or use Auto_Open as Rudi explained. The code would be something like:

    Private Sub Workbook_Open()
    ThisWorkbook.Worksheets("Sheet1").Range("A1").Valu e = Application.UserName
    End Sub

    Post back if you need more help.
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

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