Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default 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


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
(username v1) JJernigan Excel Discussion (Misc queries) 0 June 12th 08 09:13 PM
username robzrob Excel Worksheet Functions 2 May 4th 08 05:59 PM
Username Log PaulJ Excel Discussion (Misc queries) 8 March 1st 06 11:51 AM
NT Username ceemo Excel Discussion (Misc queries) 4 August 2nd 05 04:39 PM
Username Lawlera[_2_] Excel Programming 3 December 23rd 03 09:21 AM


All times are GMT +1. The time now is 02:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"