From Excel get Outlook Username

A

andy

What code would I have to use to get from within Excel to
get the Users email address from Outlook? In our system
the authentication if done from the MS network logon. The
username is always the network login name
(firstname.lastname) appended with an "@" then domain.org

I know how to add the reference to Excel to use Outlook,
but don't know how to bring this piece of data from
Outlook back into Excel. Filling a variable would work
well for me.

Thank you in advance
God bless you
 
F

Frank Kabel

Hi
try the following:
1. Put the following code in a module:
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


Now use the following function to get the email-address:
=SUBSTITUTE(UserName()," ",".") & "@domain.com"
 
Top