Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[blue]For Each OneItem In Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
Debug.Print OneItem.Subject
Next[/blue]
[green][i]' for automatic syntax highlighting see faq102-6487
[/i][/green]Option Explicit
Option Base 1
Private [b]Sub[/b] application_newmail()
[b]Dim[/b] oNameSpace [b]As[/b] NameSpace
[b]Dim[/b] oFolderInbox [b]As[/b] MAPIFolder
[b]Dim[/b] oMailItem [b]As[/b] MailItem
[b]Dim[/b] oMeeting [b]As[/b] MeetingItem
[b]Dim[/b] msg [b]As[/b] [b]Object[/b]
[b]On[/b] [b]Error[/b] [b]Resume[/b] [b]Next[/b]
[green][i]'Load the variables with the information needed
[/i][/green] [b]Set[/b] oNameSpace = Application.GetNamespace([navy]"MAPI"[/navy])
[b]Set[/b] oFolderInbox = oNameSpace.GetDefaultFolder(olFolderInbox)
oFolderInbox.Items.Sort [navy]"Received"[/navy], True
[green][i]' Loop through all the messages in the inbox
[/i][/green] [b]For[/b] [b]Each[/b] msg [b]In[/b] oFolderInbox.Items
[green][i]' Process only mail messages
[/i][/green] [b]If[/b] TypeOf msg [b]Is[/b] MailItem [b]Then[/b]
[green][i]' Set the object oMailItem to the msg object currently referenced
[/i][/green] [green][i]' in the loop
[/i][/green] [b]Set[/b] oMailItem = msg
[green][i]'Check the message subject for quote request
[/i][/green] [green][i]'if it is, then create a task for it and delete the email
[/i][/green] [b]If[/b] InStr(LCase(oMailItem.Subject), [navy]"pqr"[/navy]) > 0 [b]Or[/b] _
InStr(LCase(oMailItem.Subject), [navy]"rfq"[/navy]) > 0 [b]Or[/b] _
InStr(LCase(oMailItem.Subject), [navy]"ccqr"[/navy]) > 0 [b]And[/b] _
InStr(LCase(oMailItem.Body), [navy]"estimator is kirk thomas"[/navy]) > 0 [b]Then[/b]
[green][i]'This is where the actual task is created
[/i][/green] [b]With[/b] oMailItem
NewTask .SenderName, .Subject, .Body, .Attachments
[b]End[/b] [b]With[/b]
[green][i]'Delete the email since we don't need it any longer
[/i][/green] oMailItem.Delete
[b]End[/b] [b]If[/b]
[b]End[/b] [b]If[/b]
[b]Next[/b]
[green][i]'Release the objects from memory after use
[/i][/green] [b]Set[/b] oMailItem = [b]Nothing[/b]
[b]Set[/b] oFolderInbox = [b]Nothing[/b]
[b]Set[/b] oNameSpace = [b]Nothing[/b]
[b]End[/b] [b]Sub[/b]