Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Retrieve information from one workbook to another | Excel Discussion (Misc queries) | |||
Macro to retrieve information | Excel Discussion (Misc queries) | |||
Macro user defined function row information | Excel Programming | |||
Creating a macro to let a user use a keystroke for repeatative information | Excel Programming | |||
How to retrieve domain user name in macro | Excel Programming |