Excel VBA Outlook Application, How To Send From Different Address

OstinatoFreak 6 Reputation points

I have two e-mail addresses. Let's say my default account is default@customdomain.com, and my secondary e-mail is gmail@Stuff .com.

I need to use my secondary e-mail account (Gmail) whenever I use my Excel VBA button to send e-mail. I usually remember to change the "From" field to my secondary e-mail account, but sometimes I don't remember.

I tried to force it to use my Gmail account, but nothing I do works. Here is my current code (which all works, except the last few lines with all the xMItemproperties):

Dim xOTApp As Object  
    Dim xMItem As Object  
    Dim xCell As Range  
    Dim xRg As Range  
    Dim xEmailAddr As String  
    Dim xTxt As String  
    On Error Resume Next  
    xTxt = ActiveWindow.RangeSelection.Address  
    Set xRg = Range("i2:i7")  
    Set xOTApp = CreateObject("Outlook.Application")  
    For Each xCell In xRg  
        If xCell.Value Like "*@*" Then  
            If xEmailAddr = "" Then  
                xEmailAddr = xCell.Value  
                xEmailAddr = xEmailAddr & ";" & xCell.Value  
            End If  
        End If  
    Set xMItem = xOTApp.CreateItem(0)  
    With xMItem  
        .Bcc = xEmailAddr  
        .Sender = "gmail@gmail.com"  
        .SenderEmailAddress = "gmail@gmail.com"  
        .SendUsingAccount = "gmail@gmail.com"  
'        .SenderName = "My Name"  
    End With  
End Sub  

Not one of these properties does a darned thing. The e-mail just pops up using my default@customdomain.com account, and doesn't even display my name (so not even ".SenderName" is working).

{count} vote