Hi
This should be the one but be aware that this is easy for the user to change thru tools>options>general.
Code:
Application.UserName
Dunno how this works on a network where the corp would be the licensee.....
;-)
If a man says something and there are no women there to hear him, is he still wrong?
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
As Loomah says Username can easily be changed so perhaps the login name may be more useful?
Try this macro
Option Explicit
Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
(ByVal lpName As String, _
ByVal lpUserName As String, _
lpnLength As Long) As Long
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)
MsgBox "User Name is " & strUn
Else
MsgBox "Error :" & lngUser
End If
End Sub
just another (shorter) way
myUser = environ("username"
Rgds, Geoff [blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
Picked up the code a coupla years ago from an excel developers list that I subscribe to. There are indeed other "environ" functions. Run this to find 'em out:
Sub env()
Dim EnvString As String
Indx = 1
Do
EnvString = Environ(Indx)
Cells(Indx, 1) = EnvString
Indx = Indx + 1
Loop Until EnvString = ""
End Sub
Rgds, Geoff [blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
Thanks steve - 5 is the visual limit - AFAIK, any amount of stars can be awarded for a post but I think this is the 1st time I've reached the visual limit - woo yay !!
Rgds, Geoff [blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
Used environ("username" a hundred times and never thought to post it here!!!
Just a little addition for anyone still taking any notice - you can also get a list of the available environment variables through DOS by using the 'Set' command/keyword.
;-)
If a man says something and there are no women there to hear him, is he still wrong?
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
Does environ("username" work in XL97? It returns blank for me (although the little SUB above does list out 9 other environ() variables that are available to me).
environ("username" does work in xl97 but not on all OS's - I used to think it only worked on NT but have since moved to XP and it still works. It may be that it doesn't work for your particular OS......
Rgds, Geoff [blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.