+ Reply to Thread
Results 1 to 15 of 15

Display name of outlook current user via excel-VBA

Hybrid View

Alicita Display name of outlook... 02-10-2011, 05:10 PM
Alicita Re: Display name of outlook... 02-11-2011, 08:05 AM
snb Re: Display name of outlook... 02-11-2011, 08:23 AM
Alicita Re: Display name of outlook... 02-11-2011, 08:33 AM
Alicita Re: Display name of outlook... 02-11-2011, 08:06 PM
snb Re: Display name of outlook... 02-12-2011, 11:10 AM
Alicita Re: Display name of outlook... 02-14-2011, 08:41 AM
snb Re: Display name of outlook... 02-14-2011, 08:45 AM
Alicita Re: Display name of outlook... 02-14-2011, 09:19 AM
snb Re: Display name of outlook... 02-14-2011, 09:29 AM
Alicita Re: Display name of outlook... 02-14-2011, 09:57 AM
snb Re: Display name of outlook... 02-14-2011, 10:22 AM
Alicita Re: Display name of outlook... 02-14-2011, 10:40 AM
snb Re: Display name of outlook... 02-14-2011, 12:41 PM
Alicita Re: Display name of outlook... 02-14-2011, 02:02 PM
  1. #1
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Display name of outlook current user via excel-VBA

    Hello! I'm trying to find the name of the current user of outlook.
    I'm writing an automated email via excel-VBA, and at the end of the email, I want to write the name of the current user.

    I've tried this:

    Sub name()
    Dim username As String, Ln As Long
    Set wn = CreateObject("Wscript.Network")
    username = WshNetwork.username
    MsgBox (username)
    
    End Sub
    But I only get the user name of windows..

    And then I tried this:
    Sub username()
    
    Set objSession = CreateObject("MAPI.Session")
    
    ' Logon using an existing MAPI session
    objSession.Logon "", "", False, False, 0
    
    ' Get folder where the current Outlook item lives
    Set objFolder = Item.Parent
    
    ' Get the Outlook item with CDO
    Set objMessage = objSession.GetMessage(Item.EntryID, objFolder.StoreID)
    
    ' Get the sender of the message
    Set objSender = objMessage.Sender
    
    ' Pull out some properties of the sender
    MsgBox ("Sender name: " & objSender.Name)
    MsgBox ("Sender address: " & objSender.Address)
    
    ' Close MAPI session
    objSession.Logoff
    
    End Sub
    But a big error appears ([colaboration data objects - [MAPI_E_LOGON_FAILED(80040111)])

    Is there a simplified way for dummies? Thank you in advance
    Last edited by Alicita; 02-15-2011 at 08:12 AM.

  2. #2
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Display name of outlook current user via excel-VBA

    bump, help?

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Display name of outlook current user via excel-VBA

    what username do you want "

    Application.username
    Environ("Username")
    createobject("wscript.network").username

    Or do you want the accountname 'user@Alicita.ch'



  4. #4
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Display name of outlook current user via excel-VBA

    the user name from the e-mail account, the actual name of the sender.

    My emails from outlook are sent displaying my full name (Alice XXXX) That's what I want, is it clear? :S

    I tried your code, but I don't undestand it, and yields me an error :S

  5. #5
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Display name of outlook current user via excel-VBA

    bump for help

    snb, Thank you for your help. I managed to work with your code, but It returns the user name from windows, which I'm not looking for right now.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Display name of outlook current user via excel-VBA

    What do you get using:

    Sub snb()
      msgbox createobject("Outlook.application").Getnamespace("MAPI").CurrentUser
    End sub

  7. #7
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Display name of outlook current user via excel-VBA

    Hi! Thank you for keep helping me

    A popup windows appears "A program is trying to access e-mail addresses you have stored in Outlook"
    I click "yes" and in another popup window appears my user name of outlook (the one that I wanted!)

    Is there a way to eliminate the first pop-up without the intervention of the user?

    Thank you!!

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Display name of outlook current user via excel-VBA

    Is there a way to eliminate the first pop-up without the intervention of the user?
    1 - return to using Excel 2000
    2 - Install the freeware ClickYes

  9. #9
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Display name of outlook current user via excel-VBA

    well.. thank you anyway

    Another question, what about the username from the e-mail account, like getting XXXX (XXXX@mail.com) without the pop-up?

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Display name of outlook current user via excel-VBA

    To do what ?

  11. #11
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Display name of outlook current user via excel-VBA

    display the username from the email account

    like display Alice from Alice@mail.com

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Display name of outlook current user via excel-VBA

    I thought a messagebox is meant to display something.....
    So the code did what you asked for.

  13. #13
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Display name of outlook current user via excel-VBA

    No! arg.. I didn't explain it well enough! Sorry, english isn't my primary language (evidently)

    The pop-up box I don't want is the one asking for permission ("A program is trying to access e-mail addresses you have stored in Outlook")The other one, the MsgBox, that's ok. Now, If I can't display the name without the prompt asking for permission, can I display the user name from the e-mail account? such as displaying Alice when the e-mail account is alice@mail.com

    Thank you for your pacience!

  14. #14
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Display name of outlook current user via excel-VBA

    As soon as you try to read something from outlook you will get the unwanted question. In an earlier post I indicated how you can prevent that question to pop up.

  15. #15
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Display name of outlook current user via excel-VBA

    I see, I tought it was only THAT specific case, not everything I read from outlook.

    Thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1