PC Review


Reply
Thread Tools Rate Thread

1st time using vba with Outlook

 
 
=?Utf-8?B?Y29jbw==?=
Guest
Posts: n/a
 
      5th Sep 2005
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:(E-Mail Removed) and CC: (E-Mail Removed) and (E-Mail Removed)
step5: put email to draft

Thanks for you help

Coco
 
Reply With Quote
 
 
 
 
Michael Bauer
Guest
Posts: n/a
 
      6th Sep 2005
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)

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook

> 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:(E-Mail Removed) and CC: (E-Mail Removed) and (E-Mail Removed)
> step5: put email to draft
>
> Thanks for you help
>
> Coco

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2003: Meeting Requests: Time=Free -> Time=Tentative Craigster Microsoft Outlook Calendar 2 21st Nov 2008 05:21 AM
Appointment times in Outlook showing current time not set time =?Utf-8?B?TXJzIEJlYXI=?= Microsoft Outlook Discussion 0 6th Jul 2006 07:56 AM
Outlook, sending time delayed email with current delivery time =?Utf-8?B?Qm9iZGVhZg==?= Microsoft Outlook Discussion 0 25th Apr 2006 02:56 PM
Outlook calendar time zone: current time is 1 hour ahead of clock =?Utf-8?B?TmF0YWxpZQ==?= Microsoft Outlook Calendar 2 12th Feb 2006 05:26 AM
Outlook agenda: Uses current time in stead of time appointment Maria Microsoft Outlook Calendar 0 21st Jul 2003 12:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:51 PM.