I am not sure of the benefit of using a macro to create a rule. If you want to reply automatically to messages that contain "fun" or 'chat' in the subject, then you need to create a rule that acts on all incoming messages to run the following script. If scripts do not appear in the rules dialog - see https://www.slipstick.com/outlook/ru...-script-rules/
Option Explicit
'Graham Mayor - https://www.gmayor.com - Last updated - 14 Jan 2021
Sub AutomaticReply(olItem As Outlook.MailItem)
Dim olOutMail As Outlook.MailItem
Dim olInsp As Outlook.Inspector
Dim wdDoc As Object
Dim oRng As Object
Dim vSub As Variant
Dim i As Integer
Dim bFound As Boolean
vSub = Array("fun", "chat")
If Not TypeName(olItem) = "MailItem" Then Exit Sub
For i = 0 To UBound(vSub)
If InStr(1, LCase(olItem.Subject), vSub(i)) > 0 Then
bFound = True
Exit For
End If
Next i
If bFound = True Then
Set olOutMail = olItem.ReplyAll
With olOutMail
.BodyFormat = olFormatHTML
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oRng = wdDoc.Range
oRng.collapse 1
oRng.Text = "Yes" & vbCr 'The reply message
.Display 'required
'.Send 'enable after testing
End With
End If
lbl_Exit:
Set olOutMail = Nothing
Set olInsp = Nothing
Set wdDoc = Nothing
Set oRng = Nothing
Exit Sub
End Sub
You can run the following macro to test the code. Select a message with 'fun' or 'chat' in the subject and run the macro. If the strings are no found or the message is an meeting nothing happens.
Sub TestMacro()
Dim olMsg As MailItem
On Error Resume Next
Select Case Outlook.Application.ActiveWindow.Class
Case olInspector
Set olMsg = ActiveInspector.currentItem
Case olExplorer
Set olMsg = Application.ActiveExplorer.Selection.Item(1)
End Select
AutomaticReply olMsg
lbl_Exit:
Exit Sub
End Sub