1st time using vba with Outlook

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I have two email that I receive everyday with different subject XXX and YYY
Does VBA support an option to let me create a new email with this steps

step1: search for last email with subject XXX
step2: search for last email with subject YYY
step3: create new email with:
subject YYY
body: copy body from email found in step1
copy body from email found in step2
step4: set TO:[email protected] and CC: (e-mail address removed) and (e-mail address removed)
step5: put email to draft

Thanks for you help

Coco
 
Am Mon, 5 Sep 2005 15:27:01 -0700 schrieb coco:

Coco, the following sample handles step 1 and 2. If available then it
returns a reference on the searched MailItem. Call the function like this:

Dim oMailXXX As Outlook.MailItem
Dim colItems as Outlook.Items
set colItems=Application.Session.GetDefaultFolder(olFolderInbox).Items
Set oMailXXX=GetNewestMailItem(colItems, "XXX")


Public Function GetNewestMailItem(ByVal colItems As Outlook.Items, _
Optional sSubject As String _
) As Outlook.MailItem
Dim sFilter As String
Dim obj As Object

If colItems.Count Then
If Len(sSubject) Then
sFilter = "[Subject]=" & Chr(34) & sSubject & Chr(34)
Set colItems = colItems.Restrict(sFilter)
End If

If colItems.Count Then
colItems.Sort "ReceivedTime", True
Set obj = colItems.Item(1)
If TypeOf obj Is Outlook.MailItem Then
Set GetNewestMailItem = obj
End If
End If
End If
End Function

For step 3 please see the VBA help sample for the CreateItem function. The
mail´s body is accessable e.g. via the Body property.

Step 4: Please see samples for Recipients.Add

Step 5: Just save e-mail (Save method)
 
Back
Top