Home
FREE DOWNLOADS
VBA Tutorials
VBA CodeSamples
VBA for Beginners
Save Time News
Outlook Tutorials
Save Time Blog
SaveTime SiteMap
Excel VBA Code
PageNotActive
Other Tutorials
About This Website

Subscribe To This Site
XML RSS
Add to Google
Add to My Yahoo!
Add to My MSN
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



.

Return from Outlook VBA myMailItem Criteria to VBA Code Samples


Return to our Homepage


footer for Save Time page