logo

Microsoft Outlook VBA Tutorial


The following Microsoft Outlook VBA tutorial shows how to send an email with an automatic signature, if you have set up a signature.

Other tutorials you may want to learn from are...

Another tutorial for sending an email  (See this tutorial if your Macro security is set to High and you want to enable you code to run).
 
Save Attachments from Outlook using VBA

Outlook VBA Mailitem Criteria


Sub Mail_with_Signature()

    Dim olMailItem As MailItem
    Dim ns As NameSpace
    Dim olRecips As Recipient
    Dim tmpRecips As String
   
   
    Set ns = Application.Session
    If Not ns Is Nothing Then
        ns.Logon , , False, False
    End If
    Set olMailItem = Application.CreateItem(olMailItem)
'    olMailItem.Body = "Body of Test Email"
    tmpRecips = InputBox("Enter the recipients separated by ;")
    Set myRecips = myMailItem.Recipients.Add(tmpRecips)
    olRecips.Type = olTo
    tmpRecips = InputBox("Enter the CC recipients separated by ;")
    If InStr(tmpRecips, "@") Then
        Set olRecips = myMailItem.Recipients.Add(tmpRecips)
        olRecips.Type = olCC
    End If
    tmpRecips = InputBox("Enter the BCC recipients separated by ;")
    If InStr(tmpRecips, "@") Then
        Set olRecips = olMailItem.Recipients.Add(tmpRecips)
        olRecips.Type = olBCC
    End If
    Set olRecips = Nothing
    olMailItem.Subject = "Subject of Test Email"
    If Len(Dir("c:\\TestFile.txt")) Then
        olMailItem.Attachments.Add "c:\\TestFile.txt"
    End If
    olMailItem.Display
    olMailItem.Body = "Body of Test Email" & myMailItem.Body
    olMailItem.Send
End Sub 







Return from Microsoft Outlook VBA tutorial to our Homepage