I have created a mailmerge tool with Outlook 365 VBA. It creates emails and gives them a category and saves them in a draft folder. I then set up a sub to send the emails that have that particular category name.
When i run the mail merge to generate the emails, none of the emails have an Action of This method can’t be used with an inline response mail item.
However, when i run the sub to loop through the draft folder all the emails it finds show the correct subject title, content etc in the Watch window, but now have an Action of the above message on them. This seems to prevent the emails from being sent.
Does anyone have any ideas why? Or how to clear the Action?
Here is the sub code for the send sub
```
Sub SendEmailBatch()
Dim Out_OutlookApp As outlook.Application
Dim Out_MailItem As outlook.MailItem
Dim Obj_SendingAccount As Object
Dim Out_DeliveryFolder As outlook.Folder
Dim Wrk_WsTable As Worksheet
Dim Str_AccountName As String
Dim Str_CategoryName As String
' Create a new instance of Outlook Application
Set Out_OutlookApp = New outlook.Application
' Set reference to the worksheet
Set Wrk_WsTable = ThisWorkbook.Sheets("Table")
' Get account name from the worksheet
Str_AccountName = Wrk_WsTable.Range("G11").Value
' Get category name from the worksheet
Str_CategoryName = Wrk_WsTable.Range("G36").Value
' Find the sending account
For Each Obj_SendingAccount In Out_OutlookApp.Session.Accounts
If Obj_SendingAccount.DisplayName = Str_AccountName Then
Exit For
End If
Next Obj_SendingAccount
' If the sending account is not found among regular accounts, search among shared mailboxes
If Obj_SendingAccount Is Nothing Then
For Each Obj_SendingAccount In Out_OutlookApp.Session.Stores
If Obj_SendingAccount.DisplayName = Str_AccountName Then
Set Out_DeliveryFolder = Obj_SendingAccount.GetDefaultFolder(olFolderDrafts)
Exit For
End If
Next Obj_SendingAccount
End If
' Check if the sending account is found
If Obj_SendingAccount Is Nothing Then
MsgBox "Sending account not found.", vbExclamation
Exit Sub
End If
' Loop through the items in the drafts folder
For Each Out_MailItem In Out_DeliveryFolder.Items
' Check if the email has the specified category
If Out_MailItem.Categories = Str_CategoryName Then
' Clear conversation index to avoid it being marked as a response
Out_MailItem.ClearConversationIndex
' Set DeferredDeliveryTime to a future time to prevent inline response status
Out_MailItem.DeferredDeliveryTime = Now + TimeValue("00:01:00") ' Delay for 1 minute
' Send the email
Out_MailItem.Send
End If
Next Out_MailItem
MsgBox "Emails sent.", vbInformation
End Sub
I have tried to get ChatGPT to help and it has suggested ClearConversationIndex and to add a deferred delivery time but that hasn't worked.
Alex Scott is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.