kbsudhir
10-09-2008, 02:18 PM
Hi All,
I am trying to forward the mails in inbox which are more than 2hrs old.
Below is the code which I thought of but teh problem is sometimes it seems to work & most of the times is do not work. I am forwarding the mails to three persons.
Please let me know where I am going wrong.
Sub ForwardMails()
On Error Resume Next
Dim Fld_Path As Object
Dim Item As Object
Dim myattachments As Outlook.Attachments
'Set Fld_Path = Application.GetNamespace("MAPI").Folders("Mailbox - Mine").Folders("Inbox")
Dim CurrTme, RecTme As Date
Dim TmeDiff As Integer
CurrTme = Format(Now, "[$-409]m/d/yy h:mm AM/PM;@")
For Each Item In Fld_Path.Items
TmeDiff = DateDiff("H", Item.ReceivedTime, CurrTme)
If TmeDiff >= 2 Then
Set myattachments = Item.Attachments
If myattachments.Count > 0 Then
'
Set MyItem = Item.Forward
MyItem.Body = "This mail is in the assigned folder for more than 2Hrs"
MyItem.Recipients.add "Person1; Person2; Person3"
MyItem.Send
End If
End If
Next Item
End Sub
:doh: :doh:
Sudhir
I am trying to forward the mails in inbox which are more than 2hrs old.
Below is the code which I thought of but teh problem is sometimes it seems to work & most of the times is do not work. I am forwarding the mails to three persons.
Please let me know where I am going wrong.
Sub ForwardMails()
On Error Resume Next
Dim Fld_Path As Object
Dim Item As Object
Dim myattachments As Outlook.Attachments
'Set Fld_Path = Application.GetNamespace("MAPI").Folders("Mailbox - Mine").Folders("Inbox")
Dim CurrTme, RecTme As Date
Dim TmeDiff As Integer
CurrTme = Format(Now, "[$-409]m/d/yy h:mm AM/PM;@")
For Each Item In Fld_Path.Items
TmeDiff = DateDiff("H", Item.ReceivedTime, CurrTme)
If TmeDiff >= 2 Then
Set myattachments = Item.Attachments
If myattachments.Count > 0 Then
'
Set MyItem = Item.Forward
MyItem.Body = "This mail is in the assigned folder for more than 2Hrs"
MyItem.Recipients.add "Person1; Person2; Person3"
MyItem.Send
End If
End If
Next Item
End Sub
:doh: :doh:
Sudhir