Home
FREE DOWNLOADS
VBA Tutorials
VBA Code Samples
VBA Code - Excel
VBA for Beginners
Save Time on PC
SaveTimeWebsite
Save Time News
Save Time Blog
SaveTime SiteMap
Customer Service
Gibberish

Subscribe To
This Site

XML RSS
Add to Google
Add to My Yahoo!
Add to My MSN
Add to Newsgator
Subscribe with Bloglines

Basic Outlook VBA myMailItem Criteria

In the following code there is the basic outlook vba mymailitem criteria. If you need to explore more of the criteria options, type myMailItem followed by a period to have intellisense show these other options to you.

Option Explicit

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

Google
Return from Outlook VBA myMailItem Criteria to "VBA Code Samples"

Return to our "Home page"



footer for outlook vba mymailitem criteria page