Get users email adress from Outlook / Exchange

H

HenrikH

How do i read the users email adress using VBA in Word.

We are running Outlook 2003 and Exchange-server. We would like the
users email adresse to be automatically displayed in Word documents as
part of the signature. Of course the user could write it himself but
getting it there automatically would be more usefull.
 
G

Graham Mayor

The following will write the user's e-mail address at a bookmark called
EMail or at the cursor if there is no bookmark of that name.

Sub InsertCurrentUsersEmailAddress()
Dim olook As Outlook.Application
Dim sEAddress As String
Dim bStarted As Boolean
On Error Resume Next
Set olook = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set olook = CreateObject("Outlook.Application")
bStarted = True
End If
sEAddress = olook.Session.CurrentUser.Address
' Close Outlook if it was started by this macro.
If bStarted Then
oOutlookApp.Quit
End If
With Selection
.GoTo What:=wdGoToBookmark, name:="EMail"
.TypeText Text:=sEAddress
End With
End Sub



--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

HenrikH

The following will write the user's e-mail address at a bookmark called
EMail or at the cursor if there is no bookmark of that name.

Sub InsertCurrentUsersEmailAddress()
Dim olook As Outlook.Application
Dim sEAddress As String
Dim bStarted As Boolean
On Error Resume Next
Set olook = GetObject(, "Outlook.Application")
If Err <> 0 Then
    Set olook = CreateObject("Outlook.Application")
    bStarted = True
End If
sEAddress = olook.Session.CurrentUser.Address
'  Close Outlook if it was started by this macro.
If bStarted Then
    oOutlookApp.Quit
End If
    With Selection
        .GoTo What:=wdGoToBookmark, name:="EMail"
        .TypeText Text:=sEAddress
    End With
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>





- Vis tekst i anførselstegn -

Hi Graham

Yes i found a similar code which does the same.

But i do not get the email adress in the format
"(e-mail address removed)".

I get info like this /o=YY Organization/ou=First Administrative Group/
cn=Recipients/cn=36050 which i cannot use.
 
H

HenrikH

Seems from other internet users with similar macroes that it is not
possible to avoid the warning unless the code is written in dot.net or
you use 3. part programs.

Any suggestions Graham or anyone else ?
 

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