Hello,

I write a lot of VBA in excel, but am newer to using it within outlook. I am trying to find a way to send a reply to the person who sent an e-mail when I change the category. Here is what I have, but it does not seem to be working. Any insight would be appreciated!

Private Sub Application_Startup()
Dim Msg As Outlook.MailItem
Dim Ns as Outlook.NameSpace
Set Ns = Application.GetNamespace("MAPI")
Set Items = Ns.GetDefaultFolder(olFolderInbox).Items
Dim oRespond As Outlook.MailItem
End Sub

Private Sub Items_ItemChange(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem AND Item.Categories = "xyz" Then
Set oRespond = Application.CreateItemFromTemplate("file path here")
With oRespond
.Recipients.Add Item.SenderEmailAddress
.Subject = "Re: xyz - " & Item.Subject
.HTMLBody = oRespond.HTMLBody & vbCrLf & "--- original message attached ---" & vbCrLf & Item.HTMLBody & vbCrLf
.Attachments.Add Item
.Send
End With
Set oRespond = Nothing

ElseIf 'My macro repeats the above If statement with different category
End If
End Sub


Thank you