Basic Outlook VBA myMailItem CriteriaSub 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
|