Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Outlook Account Settings-how do I view and adjust with VBA

    I use different email addresses for different companies I deal with, eg companyx@myemail.xx.yy, businessy@myemail.xx.yy, etc, in an attempt to identify where they got my email address. (Not foolproof, for example where I am BCC'd, but it helps.)

    I can change the displayed (and return to?) email address in User Information in Change Account / Internet E-mail Settings of the E-mail Accounts window of Account Settings, so that when I send emails they appear to come from this same account.

    This is fine until I forget to change it back, and subsequent emails go out with an email address I did not intend for that recipient. (I then get multiple copies of emails from friends who get confused and send to several different addresses to make sure I get it!)

    So I would like to set up a VBA checkbox so that whenever I send an email, I can check that the correct email address is shown.

    But I can't find out how to do this, or indeed to access any Outlook Account Settings using VBA. I am using Outlook 2010. Any ideas?

    (Repost from Outlook board as no response there, and I would really like an answer, please!)
    Last edited by robm25; 2012-11-06 at 05:36. Reason: change title

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    This might get you started. I got the basic bits from http://www.programmer.bz/Articles/tabid/159/asp_net_sql/35/Outlook-Application_ItemSend-Event.aspx

    Firstly, check your macro security settings to ensure that macros are allowed to run
    Secondly, add the following macro to your ThisOutlookSession module

    Code:
    Private Sub Application_ItemSend(ByVal item As Object, cancel As Boolean)  Dim email As MailItem
      Set email = item
      If email.Class <> olMail Then Exit Sub 'Make sure it is a mail message and not a task or something else
      MsgBox "Sending from:" & email.SendUsingAccount
    End Sub
    Once this is working, you can modify the code to do what you require.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    New Lounger
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, Andrew, but this does not do what I want.

    I do have 2 accounts that I use, and it tells me which one I am using, but that is not normally the problem.

    What I am looking for is the E-mail Address in the User Information section of the Internet E-mail Settings in the Change Account box relating to the selected account. Is there any way to access this programmatically?

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Use the VBA intellisense to examine what is available in the email MailItem
    eg email.SenderEmailAddress might be what you are looking for. I only have one account setup and this property doesn't return anything for me but it might work for you.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    New Lounger
    Join Date
    Sep 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by robm25 View Post
    Thank you, Andrew, but this does not do what I want.

    I do have 2 accounts that I use, and it tells me which one I am using, but that is not normally the problem.

    What I am looking for is the E-mail Address in the User Information section of the Internet E-mail Settings in the Change Account box relating to the selected account. Is there any way to access this programmatically?
    The account is under Application.Session.Accounts - This will show you the account specific details, such as what you have the name listed as.

    What you are looking for is the USER email assigned to the account. To get this, use this line:
    Code:
    Application.Session.Accounts.Item(<replace this with the accountname or indexvalue>).CurrentUser.Address
    The code you need is as below:
    Code:
    Private Sub Test()
    MsgBox Application.Session.Accounts.Item(<replace this with the accountname or indexvalue>).CurrentUser.Address
    End Sub
    Modify as needed.

Tags for this Thread

Posting Permissions

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