writing to a cell current users name

Joe C

Well-known Member
Joined
Oct 17, 2002
Messages
841
How do you write to a cell the current users login name?
I created a series of macros to allow users to update data from pivot table data and then rerun analysis. I take the bad data to a dump sheet and would like to record who selected in case anyone questions why data was removed.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Something Colo wrote a while ago to use as an example:

Code:
Option Explicit

Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
                         (ByVal lpName As String, _
                          ByVal lpUserName As String, _
                          lpnLength As Long) As Long

Private Const NO_ERROR = 0
Private Const ERROR_NOT_CONNECTED = 2250&
Private Const ERROR_MORE_DATA = 234
Private Const ERROR_NO_NETWORK = 1222&
Private Const ERROR_EXTENDED_ERROR = 1208&
Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&

Sub WinUsername()
    Dim strBuf As String, lngUser As Long, strUn As String
    strBuf = Space$(255) '//Clear buffer
    lngUser = WNetGetUser("", strBuf, 255)
    If lngUser = NO_ERROR Then
        strUn = Left(strBuf, InStr(strBuf, vbNullChar) - 1)
        Sheets("Sheet1").Range("A11") = "User Name is  " & strUn
    Else
        Sheets("Sheet1").Range("A11") = "Error :" & lngUser
    End If
End Sub

An alternative: http://j-walk.com/ss/excel/tips/tip94.htm

Or have a search of the board on 'environ("username")' (without the single quotes)
HTH
 
Upvote 0
How about:
Code:
Sub UserName()
    Dim CurrentUserName As String
        CurrentUserName = Environ("Username")
    Sheets("Sheet1").Range("A1") = CurrentUserName
End Sub
Hope that helps,

Smitty
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,412
Members
448,959
Latest member
camelliaCase

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top