IgnoranceIsBliss
Registered User.
- Local time
- Yesterday, 16:46
- Joined
- Jun 13, 2019
- Messages
- 35
If I change as suggested I now get a error in the line
Next olMail
The error is Type Mismatch
Next olMail
The error is Type Mismatch
Debug.Print olMail.To
Debug.Print olMail.SentOn
The message above the last one printed is a meeting invite for Skype for Business.
Is there a way to search only emails?
Can have a single Debug line:
Debug.Print "TO: " & olMail.To & " ON: " & olMail.SentOn
Need to remove the Else branch.
We are above my skill set at this point.
Maybe a more advanced Access VBA user can step in here
For Each msg In Fldr.Items
Debug.Print TypeName(msg)
Next msg
Function Test()
Dim searchEmail As String: searchEmail = "'abc123@abc123.com'"
Dim olApp As Outlook.Application
Dim olNs As NameSpace
Dim Fldr As MAPIFolder
Dim olReply As Outlook.MailItem
Dim msg As Object
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderSentMail)
For Each msg In Fldr.Items
If TypeName(msg) = "MailItem" Then
If msg.To = searchEmail Then
Debug.Print "To: " & msg.To & " On: " & msg.SentOn
Set olReply = msg.ReplyAll
With olReply
'now you have control of the email you can add any text you want
.BodyFormat = olFormatHTML
.Display
End With
End If
End If
Next msg
End Function
With olReply
.BodyFormat = olFormatHTML
.HTMLBody = emailBody
.Save
.Close olSave
End With