I try to call an email from a group mailbox and reply to it. All works perfectly and as expected except for the reply aspect. I can either make a reply body (which will be the only thing in the email) and send that or open an empty reply and keep the email history (the previous messages).
I have narrowed the problem to the fact excel and outlook aren't communicating as they should. I have the correct ticket references in both applications and ensured this is the problem by running some dummy code below that also fails.
Sub Find_Email()
Dim objOutlook As Object: Set objOutlook = CreateObject("Outlook.Application")
Dim olMail As Outlook.MailItem
Dim olReply As Outlook.MailItem
Dim olNS As Namespace: Set olNS = GetNamespace("MAPI")
Dim olMailbox As Folder: Set olMailbox = olNS.Folders("Group Inbox")
Dim olFolder As Folder: Set olFolder = olMailbox.Folders("Group Folder")
Dim subFolder As Folder: Set subFolder = olFolder.Folders("Group Subfolder")
Dim olItems As Outlook.Items: Set olItems = subFolder.Items
TheDate = Format(Date, "DD-MM-YYYY")
TheDate1 = Format(Date, "YYYY-MM")
TheDate2 = Format(Date, "YYYYMMDD")
TheDate3 = Format(Date, "YYYY")
'Find most recent email and populate
olItems.Sort "ReceivedTime", True
For i = 1 To 20 'used to be olItems.Count
Set olMail = olItems(i)
If InStr(olMail.Subject, "Subject " & TheDate) > 0 Then
Set olReply = olMail.ReplyAll
With olReply
'.To = "Recipients"
'.CC = ""
'.Subject = "anything" & TheDate
.HTMLBody = EmailBody & .HTMLBody
If Attach_File = True Then: olReply.Attachments.Add "Location"
.Display
Exit Sub
End With
End If
Next i
End Sub
' Fails at .HTMLBody as application-defined error or object-defined error
Dummy Code: Outlook:
Function testoutlook()
Call MsgBox("hello")
End Function
Excel:
Sub testexcel()
Dim o As Outlook.Application
Set o = GetObject("", "Outlook.application")
o.Application.testoutlook
End Sub
'This fails at the function call, Object doesn't support this property or method