From Excel get Outlook Username

  • Thread starter Thread starter andy
  • Start date Start date
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
 
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"
 

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

Back
Top