![]() |
Get NT Username
Hi,
I trying to create a spreadsheet that when you go in, depending on what user you are, you can see different worksheets sheets. I figure I can do this, if I could first determine the user that is logged on via on our NT network. I there a formula / function in ExcelXP that can do this Regards Steven |
Get NT Username
No built-in, but you can do it with a UDF.
Here is a function to do it Public Declare Function GetUserName Lib "advapi32.dll" _ Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) As Long Public Function UserName() As String Dim sName As String * 256 Dim cChars As Long cChars = 256 If GetUserName(sName, cChars) Then UserName = Left$(sName, cChars - 1) End If End Function The worksheet cell could then use =UserName() -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Steven Pugh" wrote in message ... Hi, I trying to create a spreadsheet that when you go in, depending on what user you are, you can see different worksheets sheets. I figure I can do this, if I could first determine the user that is logged on via on our NT network. I there a formula / function in ExcelXP that can do this Regards Steven |
Get NT Username
Building Functions is my Achilles heal in excel and I'm not sure how to
implement this Regards Steven "Bob Phillips" wrote in message ... No built-in, but you can do it with a UDF. Here is a function to do it Public Declare Function GetUserName Lib "advapi32.dll" _ Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) As Long Public Function UserName() As String Dim sName As String * 256 Dim cChars As Long cChars = 256 If GetUserName(sName, cChars) Then UserName = Left$(sName, cChars - 1) End If End Function The worksheet cell could then use =UserName() -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Steven Pugh" wrote in message ... Hi, I trying to create a spreadsheet that when you go in, depending on what user you are, you can see different worksheets sheets. I figure I can do this, if I could first determine the user that is logged on via on our NT network. I there a formula / function in ExcelXP that can do this Regards Steven |
Get NT Username
On a worksheet, hit Alt-F11. This takes you into the VBE. On the Insert
menu, select module. In the window that pops up, paste the code that I supplied, and then you can use it as I showed. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Steven Pugh" wrote in message ... Building Functions is my Achilles heal in excel and I'm not sure how to implement this Regards Steven "Bob Phillips" wrote in message ... No built-in, but you can do it with a UDF. Here is a function to do it Public Declare Function GetUserName Lib "advapi32.dll" _ Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) As Long Public Function UserName() As String Dim sName As String * 256 Dim cChars As Long cChars = 256 If GetUserName(sName, cChars) Then UserName = Left$(sName, cChars - 1) End If End Function The worksheet cell could then use =UserName() -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Steven Pugh" wrote in message ... Hi, I trying to create a spreadsheet that when you go in, depending on what user you are, you can see different worksheets sheets. I figure I can do this, if I could first determine the user that is logged on via on our NT network. I there a formula / function in ExcelXP that can do this Regards Steven |
Get NT Username
Bob,
Cool trick & works great! However, I'm confused as to what the if statement is doing? When does it do the Left$ and when doesn't it? Is there information about the various librarys/Controls such as advapi32.dll? David |
Get NT Username
David,
The If statement is serving two purposes. It is issuing and checking the call to the API in one statement. If GeteUserName is not successful, it returns a 0, which will resolve to false in that statement. If it is successful, it retunes 1, and the following statement strips off the null terminator which is a common need when working with APIs. To get more details about APIs, I suggest checking out www.allapi.net, and/or getting Dan Appleman's guide to the Win32 API. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "David Fixemer" wrote in message ... Bob, Cool trick & works great! However, I'm confused as to what the if statement is doing? When does it do the Left$ and when doesn't it? Is there information about the various librarys/Controls such as advapi32.dll? David |
Get NT Username
Fantastic cheers
Steven "Bob Phillips" wrote in message ... David, The If statement is serving two purposes. It is issuing and checking the call to the API in one statement. If GeteUserName is not successful, it returns a 0, which will resolve to false in that statement. If it is successful, it retunes 1, and the following statement strips off the null terminator which is a common need when working with APIs. To get more details about APIs, I suggest checking out www.allapi.net, and/or getting Dan Appleman's guide to the Win32 API. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "David Fixemer" wrote in message ... Bob, Cool trick & works great! However, I'm confused as to what the if statement is doing? When does it do the Left$ and when doesn't it? Is there information about the various librarys/Controls such as advapi32.dll? David |
Get NT Username
That's odd, David became Steven in the reply<VBG
-- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Steven Pugh" wrote in message ... Fantastic cheers Steven "Bob Phillips" wrote in message ... David, The If statement is serving two purposes. It is issuing and checking the call to the API in one statement. If GeteUserName is not successful, it returns a 0, which will resolve to false in that statement. If it is successful, it retunes 1, and the following statement strips off the null terminator which is a common need when working with APIs. To get more details about APIs, I suggest checking out www.allapi.net, and/or getting Dan Appleman's guide to the Win32 API. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "David Fixemer" wrote in message ... Bob, Cool trick & works great! However, I'm confused as to what the if statement is doing? When does it do the Left$ and when doesn't it? Is there information about the various librarys/Controls such as advapi32.dll? David |
All times are GMT +1. The time now is 06:38 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com