Sub MyRule(Item As Outlook.MailItem)
'Your custom VBA code goes here'
End Sub
MyRuleto the name you want to give the script.
'Your custom VBA code goes here'with your code.
Sub CategorizeBySender(Item As Outlook.MailItem)
Select Case LCase(Item.SenderName)
Case "bob jones", "sam smith", "jane doe"
Item.Categories = "Business"
Case "tom davis", "mary wilson"
Item.Categories = "Friends"
Case Else
Item.Categories = "Unknown"
End Select
Item.Save
End Sub
Sub SaveAttachmentsToFolder(Item As Outlook.MailItem)
Dim objFSO As Object, _
olkAttachment As Outlook.Attachment, _
strFolderName As String
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each olkAttachment In Item.Attachments
'Change the root folder path on the following line as needed'
strFolderName = "C:\RootFolder\" & objFSO.GetExtensionName(olkAttachment.FILENAME)
If Not objFSO.FolderExists(strFolderName) Then
objFSO.CreateFolder strFolderName
End If
olkAttachment.SaveAsFile strFolderName & "\" & olkAttachment.FILENAME
Next
Set objFSO = Nothing
Set olkAttachment = Nothing
End Sub
Sub AutoCreateContact(Item As Outlook.MailItem)
Dim olkContacts As Object, _
olkContact As ContactItem, _
strAddress As String, _
strName As String
Set olkContacts = Application.Session.GetDefaultFolder(olFolderContacts)
strName = Item.SenderName
strAddress = Item.SenderEmailAddress
Set olkContact = olkContacts.Items.Find("[FullName] = " & Chr(34) & strName & Chr(34))
If TypeName(olkContact) = "Nothing" Then
If Item.SenderEmailType = "SMTP" Then
Set olkContact = Application.CreateItem(olContactItem)
With olkContact
.Email1Address = strAddress
.FullName = strName
'Change or remove the following line as desired'
.Body = "Record created automatically on " & Date & " at " & Time & " by BlueDevilFan's script."
'Create a similar IF ... END IF sequence for each category you want to add'
If InStr(1, Item.Body, "TechRepublic") Then
.Categories = AddCategory(.Categories, "TechRepublic")
End If
.Save
End With
End If
End If
Set olkContact = Nothing
Set olkContacts = Nothing
End Sub
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (1)
Commented:
Example if subject is "bob jones" the rule triggers
but if subject is "bob jones - what will we do today" the rule does not trigger. I have tried using "*bob jones*" without success. Please help on how to proceed.