+ Reply to Thread
Results 1 to 3 of 3

Select specific mail account with vba

Hybrid View

loroverde Select specific mail account... 10-02-2017, 01:19 AM
Keebellah Re: Select specific mail... 10-02-2017, 02:16 AM
Keebellah Re: Select specific mail... 10-02-2017, 02:19 AM
  1. #1
    Registered User
    Join Date
    07-27-2013
    Location
    Peru
    MS-Off Ver
    Excel 2003
    Posts
    24

    Select specific mail account with vba

    Hello
    I have 2 mails accounts (rh@hotmail.com and bp@gmail.com)
    I would like to select by vba one specific account (for example, From=rh@hotmail.com)
    when I send the mail.

    Any caritative soul could help me?

    this is part of my code

    With OutMail
    
            .To = destinatario
            .CC = ""
            .BCC = ""
            .Subject = "Cotización penprom.com"
            .HTMLBody = EmailBody & StrSignature
            .Importance = olImportanceHigh
            .Attachments.Add "C:\Users\Claudio\OneDrive\Penprom\Cotizaciones\Cot_2017\pp_cot_2017_pdf\" & ("#") & Range("B1") & ("--") & Range("r1").Value & Format(Date, "ddmmmyyyy") & ("-") & Range("B3") & ("-") & "pp.pdf"
    .Display
           
        End With

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Select specific mail account with vba

    Buenosdías,
    Are you using Outlook with these accounts linked to your Outlook?
    I have a routine that lists all my Outlook accounts it's embedded in a userform but this is the main idea
    
    Dim oAccount As Outlook.Account
    Dim oMail As Outlook.MailItem
    For Each oAccount In Application.Session.Accounts
        If oAccount = Me.ComboBox1.Value Then
            Unload Me
            Set oMail = Application.CreateItem(olMailItem)
            oMail.SendUsingAccount = oAccount
            oMail.Display
            Exit For
        End If
    Next
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Select specific mail account with vba

    This is the calling macro

    Public Sub New_Mail()
    Dim oAccount As Outlook.Account
    Load AccountSelect
    With AccountSelect
        .ComboBox1.Clear
        For Each oAccount In Application.Session.Accounts
            .ComboBox1.AddItem oAccount
            ' If InStr(1, oAccount, "(HC&TS)") > 0 Then .ComboBox1.Value = oAccount
        Next
        .Show
    End With
    Unload AccountSelect
    End Sub
    Create a userform and name it Accountselect
    One comboox and two command buttons

    Private Sub BtnCancel_Click()
    Unload Me
    End Sub
    
    Private Sub BtnOK_Click()
    If Len(Trim(Me.ComboBox1.Value)) = 0 Then Exit Sub
    
    Dim oAccount As Outlook.Account
    Dim oMail As Outlook.MailItem
    For Each oAccount In Application.Session.Accounts
        If oAccount = Me.ComboBox1.Value Then
            Unload Me
            Set oMail = Application.CreateItem(olMailItem)
            oMail.SendUsingAccount = oAccount
            oMail.Display
            Exit For
        End If
    Next
    BtnCancel_Click
    End Sub
    
    Private Sub ComboBox1_Change()
    BtnOK_Click
    End Sub
    Name you command buttons accordingly ...

    And all this in the Outlook VBA

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Create E-mails in a G-Mail account with attachments using VBA
    By spiwere in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 05-26-2017, 02:54 PM
  2. Macro to open new mail from template and from different than default account
    By taylorsm in forum Outlook Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2017, 04:51 PM
  3. Sendig mail from Gmail account
    By Hamzaoui in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-05-2015, 08:49 AM
  4. Send mail from outlook by selecting particular account
    By mukeshbaviskar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-16-2013, 11:36 AM
  5. Replies: 0
    Last Post: 01-31-2013, 06:15 AM
  6. Send e-mail on behalf of a 3rd account VBA
    By dianao in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-17-2010, 04:42 AM
  7. Mail Merge Indicated Account Details
    By Ctxited in forum Excel General
    Replies: 1
    Last Post: 09-11-2006, 09:11 AM

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