Hi,
Im having an issue with my script not running automatically. I have a script where i want it to highligh certain keywords in incoming emails. Ive tested this script and it works, it even worked automatically in the beginning for incoming emails, then suddenly it stops working and i just cant get whats wrong. Im kind of new to this and therefore not an experienced user. So i need all the help i can get.
Im having an issue with my script not running automatically. I have a script where i want it to highligh certain keywords in incoming emails. Ive tested this script and it works, it even worked automatically in the beginning for incoming emails, then suddenly it stops working and i just cant get whats wrong. Im kind of new to this and therefore not an experienced user. So i need all the help i can get.
Code:
Public WithEvents GMailItems As Outlook.Items
'UpdatebyExtendoffice20181106
Private Sub Application_Startup()
Set GMailItems = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub GMailItems_ItemAdd(ByVal Item As Object)
If Item.Class <> olMail Then Exit Sub
AutoHighlight_SpecificWords Item
End Sub
Sub AutoHighlight_SpecificWords(Mail As Outlook.MailItem)
Dim xWord As Variant
Dim xHTMLBody As String, xStr As String
Dim xWordArr
On Error Resume Next
xWordArr = Array("Order nr", "Name", "Address", "Workplace") 'keyword
xHTMLBody = Mail.HTMLBody
For Each xWord In xWordArr
If InStr(xHTMLBody, xWord) > 0 Then
xStr = "<font style=" & Chr(34) & "background-color: yellow" & Chr(34) & ">" & xWord & "</font>"
xHTMLBody = Replace(xHTMLBody, xWord, xStr)
Mail.HTMLBody = xHTMLBody
End If
Next
Mail.Save
End Sub