none
Set Default Email Sending Account with VBA RRS feed

  • Question

  • Is there a way to change the default email sending account with VBA ?

    Kindly advise

    Thank you.


    TS Lim

    Thursday, March 1, 2012 2:20 AM

Answers

  • Look on that

    Single mail:

    Option ExplicitSub Wiadomosc_z_innego_konta()
    'MVP OShon from VBATools.pl
    Dim objMailItem As MailItem, strHTML$
    Dim olNS As Outlook.NameSpace
    Set olNS = Application.GetNamespace("MAPI")
    Set objMailItem = Application.CreateItem(olMailItem)
    
    strHTML = "<Body>" _
    & "This mail is redy to go from 2nd account." & "</Body>"
    
    With objMailItem
     .BodyFormat = olFormatHTML
     .To = "test@VBATools.pl"
     .Subject = "Email subject"
     .HTMLBody = strHTML
     .SendUsingAccount = olNS.Accounts.item(2) '2nd account, work at 2007/10
     '.SentOnBehalfOfName = "test2@VBATools.pl" '2nd email to reply 
     .Display 'or .Send
    End With
    
    Set objMailItem = Nothing
    Set olNS = Nothing
    End Sub


    or event method to send (Application_ItemSend) or whose from interface link


    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    • Marked as answer by TS Lim Friday, March 2, 2012 12:44 AM
    Thursday, March 1, 2012 8:33 AM
  • Not the default account, no.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "TS Lim" <=?utf-8?B?VFMgTGlt?=> wrote in message news:1c7c4365-76e2-4b73-aa5c-90dd382998b8...

    Is there a way to change the default email sending account with VBA ?

    Kindly advise

    Thank you.


    TS Lim


    Ken Slovak MVP - Outlook
    • Marked as answer by TS Lim Friday, March 2, 2012 12:45 AM
    Thursday, March 1, 2012 3:11 PM
    Moderator

All replies

  • Look on that

    Single mail:

    Option ExplicitSub Wiadomosc_z_innego_konta()
    'MVP OShon from VBATools.pl
    Dim objMailItem As MailItem, strHTML$
    Dim olNS As Outlook.NameSpace
    Set olNS = Application.GetNamespace("MAPI")
    Set objMailItem = Application.CreateItem(olMailItem)
    
    strHTML = "<Body>" _
    & "This mail is redy to go from 2nd account." & "</Body>"
    
    With objMailItem
     .BodyFormat = olFormatHTML
     .To = "test@VBATools.pl"
     .Subject = "Email subject"
     .HTMLBody = strHTML
     .SendUsingAccount = olNS.Accounts.item(2) '2nd account, work at 2007/10
     '.SentOnBehalfOfName = "test2@VBATools.pl" '2nd email to reply 
     .Display 'or .Send
    End With
    
    Set objMailItem = Nothing
    Set olNS = Nothing
    End Sub


    or event method to send (Application_ItemSend) or whose from interface link


    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    • Marked as answer by TS Lim Friday, March 2, 2012 12:44 AM
    Thursday, March 1, 2012 8:33 AM
  • Not the default account, no.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "TS Lim" <=?utf-8?B?VFMgTGlt?=> wrote in message news:1c7c4365-76e2-4b73-aa5c-90dd382998b8...

    Is there a way to change the default email sending account with VBA ?

    Kindly advise

    Thank you.


    TS Lim


    Ken Slovak MVP - Outlook
    • Marked as answer by TS Lim Friday, March 2, 2012 12:45 AM
    Thursday, March 1, 2012 3:11 PM
    Moderator
  • Hi Oskar,

    Thank you for your solution.

    It solved my problem with:

    .SendUsingAccount = olNS.Accounts.item(2) '2nd account, work at 2007/10

    from your codes.


    TS Lim

    Friday, March 2, 2012 12:43 AM
  • My pleasure.

    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    Friday, March 2, 2012 8:18 AM
  • This code has given me great clues for my first venture into Excel+VBA;  I have my own sub for email sending and uses different senders depending on spreadsheet context.  Great stuff!    Just learning the subtleties of Worksheet_SelectionChange and Worksheet_Change...
    Friday, September 1, 2017 4:59 PM