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

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Outlook Account Settings-how do I view and adjust with VBA

    Author
    Topic
    #486200

    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!)

    Viewing 2 reply threads
    Author
    Replies
    • #1355136

      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.

    • #1356190

      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?

      • #1465930

        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().CurrentUser.Address

        The code you need is as below:

        Code:
        Private Sub Test()
        MsgBox Application.Session.Accounts.Item().CurrentUser.Address
        End Sub
        

        Modify as needed.

    • #1356484

      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.

    Viewing 2 reply threads
    Reply To: Outlook Account Settings-how do I view and adjust with VBA

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: