![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Sheffield, UK
Posts: 249
|
When someone logs onto the network where I work, a system variable called FNAM holds their name. I can get at this in DOS, but is there any way I can get to it in Excel?
|
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
|
Quote:
if yes, copy this into a module: Option Explicit ' This is used by GetUserName() to find the current user's ' name from the API Declare Function Get_User_Name Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, _ nSize As Long) As Long Function GetUserName() As String Dim lpBuff As String * 25 Get_User_Name lpBuff, 25 GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1) End Function hope this helps.
__________________
"Have a good time......all the time" Ian Mac |
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Sheffield, UK
Posts: 249
|
Wow! That is a very cool piece of code! It does almost what I want, but it is returning "smithj" (which if you type "SET" in DOS is the system variable UNAM) wheras what I want is "John Smith", which is the system variable FNAM. This code must be very close to what I need, but I don't know how to modify it. Incidentally, we are networked on Windows 95, soon to be upgraded to 2000.
Thanks for your help so far, Phil |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: May 2002
Location: Gothenburg, Sweden
Posts: 74
|
Try
s=Environ("FNAM")
__________________
/Niklas Jansson |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Sheffield, UK
Posts: 249
|
Excellent! That works perfectly. Thank you
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|