Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
(username v1) | Excel Discussion (Misc queries) | |||
username | Excel Worksheet Functions | |||
Username Log | Excel Discussion (Misc queries) | |||
NT Username | Excel Discussion (Misc queries) | |||
Username | Excel Programming |