Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieve information from one workbook to another Help with cell function[_2_] Excel Discussion (Misc queries) 2 October 22nd 09 03:01 PM
Macro to retrieve information Unique713 Excel Discussion (Misc queries) 2 November 25th 08 04:05 PM
Macro user defined function row information bj Excel Programming 4 March 9th 05 02:59 PM
Creating a macro to let a user use a keystroke for repeatative information Kelt Excel Programming 3 June 1st 04 06:15 PM
How to retrieve domain user name in macro Terence Excel Programming 1 August 11th 03 08:32 AM


All times are GMT +1. The time now is 11:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"