User Name

G

Gina Liddle

I need the UserName value so to loop through and match a
PivotField.PivotItem. I used the below code giving the said value:

Application.UserName = Tom Smith

But what I really need is TS which is the Network Login. Does anyone know
how to get this value. And if not how would I reference a spreadsheet that
contains the PivotItem values and their associated full names, looping
through to get the correct UserName?

Ta



--

Regards,

Gina


HTA Architects
Tel: 020 74828054
Email: (e-mail address removed)
 
D

Dave Peterson

In a general module:

Option Explicit

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function

'and just to test it
Sub testme()
MsgBox fOSUserName
End Sub
 
G

Gina Liddle

Thanks Dave, that works brilliantly.


Dave Peterson said:
In a general module:

Option Explicit

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function

'and just to test it
Sub testme()
MsgBox fOSUserName
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top