+ Reply to Thread
Results 1 to 5 of 5

Macro to retrieve user information

  1. #1
    Randy
    Guest

    Macro to retrieve user information

    I have a need for a function or macro to retrieve the currently logged on
    user name. Has anyone done this before or know how to do this? Also, would
    the same thing work for Word? I'm running Office 2003.

    Thanks!

    Randy

  2. #2
    Jim Thomlinson
    Guest

    RE: Macro to retrieve user information

    try this line of code

    msgbox environ("userName")

    --
    HTH...

    Jim Thomlinson


    "Randy" wrote:

    > I have a need for a function or macro to retrieve the currently logged on
    > user name. Has anyone done this before or know how to do this? Also, would
    > the same thing work for Word? I'm running Office 2003.
    >
    > Thanks!
    >
    > Randy


  3. #3
    Randy
    Guest

    RE: Macro to retrieve user information

    Jim,

    Thanks for your response. After some late night searching, I found this code:

    Private Sub Workbook_Open()
    Dim rng As Range
    Set rng = Sheets("Approvals").Range("A1").End(xlUp).Offset(0, 0)
    rng.Value = Environ("UserName")
    rng.Offset(0, 1) = Now()
    End Sub

    It works great but I need some minor modifications. I really do not know
    anything about vba and am hoping you can help. The code puts the current
    logged on user in one cell and the date and time in the next cell. The date
    shows as 8/3/2006 8:22 in the cell and as 8/3/2006 8:22:53 AM in the formula
    bar. How can I modify this code to display the entire date format?

    Thanks again!

    Randy

    "Jim Thomlinson" wrote:

    > try this line of code
    >
    > msgbox environ("userName")
    >
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "Randy" wrote:
    >
    > > I have a need for a function or macro to retrieve the currently logged on
    > > user name. Has anyone done this before or know how to do this? Also, would
    > > the same thing work for Word? I'm running Office 2003.
    > >
    > > Thanks!
    > >
    > > Randy


  4. #4
    Randy
    Guest

    RE: Macro to retrieve user information

    Jim,

    Besides the date fix above, I need to know how to undo an action caused by a
    control box. I added two check boxes (yes,no) to my sheet and attached the
    above macro to each of them. So, when either of the boxes is checked, then
    the username and date stamp are displayed. I need to know how to clear this
    information if the checkbox becomes unchecked.

    Thanks!

    Randy

    "Randy" wrote:

    > Jim,
    >
    > Thanks for your response. After some late night searching, I found this code:
    >
    > Private Sub Workbook_Open()
    > Dim rng As Range
    > Set rng = Sheets("Approvals").Range("A1").End(xlUp).Offset(0, 0)
    > rng.Value = Environ("UserName")
    > rng.Offset(0, 1) = Now()
    > End Sub
    >
    > It works great but I need some minor modifications. I really do not know
    > anything about vba and am hoping you can help. The code puts the current
    > logged on user in one cell and the date and time in the next cell. The date
    > shows as 8/3/2006 8:22 in the cell and as 8/3/2006 8:22:53 AM in the formula
    > bar. How can I modify this code to display the entire date format?
    >
    > Thanks again!
    >
    > Randy
    >
    > "Jim Thomlinson" wrote:
    >
    > > try this line of code
    > >
    > > msgbox environ("userName")
    > >
    > > --
    > > HTH...
    > >
    > > Jim Thomlinson
    > >
    > >
    > > "Randy" wrote:
    > >
    > > > I have a need for a function or macro to retrieve the currently logged on
    > > > user name. Has anyone done this before or know how to do this? Also, would
    > > > the same thing work for Word? I'm running Office 2003.
    > > >
    > > > Thanks!
    > > >
    > > > Randy


  5. #5
    Randy
    Guest

    RE: Macro to retrieve user information

    Okay, I've come up with this macro that works great! Only need to know how
    to do the date formatting.

    Private Sub CheckBox1_Click()
    If CheckBox1 = True Then
    Dim rng As Range
    Set rng = Sheets("Approvals").Range("B2").End(xlUp).Offset(1, 0)
    rng.Value = Environ("UserName")
    rng.Offset(0, 1) = Now()
    Else
    Set rng = Sheets("Approvals").Range("B2:C2")
    rng.ClearContents
    End If
    End Sub

    Private Sub CheckBox2_Click()
    If CheckBox2 = True Then
    Dim rng As Range
    Set rng = Sheets("Approvals").Range("B2").End(xlUp).Offset(3, 0)
    rng.Value = Environ("UserName")
    rng.Offset(0, 1) = Now()
    Else
    Set rng = Sheets("Approvals").Range("B4:C4")
    rng.ClearContents
    End If
    End Sub

    Randy

    "Randy" wrote:

    > Jim,
    >
    > Besides the date fix above, I need to know how to undo an action caused by a
    > control box. I added two check boxes (yes,no) to my sheet and attached the
    > above macro to each of them. So, when either of the boxes is checked, then
    > the username and date stamp are displayed. I need to know how to clear this
    > information if the checkbox becomes unchecked.
    >
    > Thanks!
    >
    > Randy
    >
    > "Randy" wrote:
    >
    > > Jim,
    > >
    > > Thanks for your response. After some late night searching, I found this code:
    > >
    > > Private Sub Workbook_Open()
    > > Dim rng As Range
    > > Set rng = Sheets("Approvals").Range("A1").End(xlUp).Offset(0, 0)
    > > rng.Value = Environ("UserName")
    > > rng.Offset(0, 1) = Now()
    > > End Sub
    > >
    > > It works great but I need some minor modifications. I really do not know
    > > anything about vba and am hoping you can help. The code puts the current
    > > logged on user in one cell and the date and time in the next cell. The date
    > > shows as 8/3/2006 8:22 in the cell and as 8/3/2006 8:22:53 AM in the formula
    > > bar. How can I modify this code to display the entire date format?
    > >
    > > Thanks again!
    > >
    > > Randy
    > >
    > > "Jim Thomlinson" wrote:
    > >
    > > > try this line of code
    > > >
    > > > msgbox environ("userName")
    > > >
    > > > --
    > > > HTH...
    > > >
    > > > Jim Thomlinson
    > > >
    > > >
    > > > "Randy" wrote:
    > > >
    > > > > I have a need for a function or macro to retrieve the currently logged on
    > > > > user name. Has anyone done this before or know how to do this? Also, would
    > > > > the same thing work for Word? I'm running Office 2003.
    > > > >
    > > > > Thanks!
    > > > >
    > > > > Randy


+ 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