I am trying to fix this macro, can someone help. I am trying to delete emails that have contain the work datascape inside attached PDF to the email.
Sub ReadEmailsAndDelete()
Dim myOlApp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myItem As Object
Dim myAttachments As Outlook.Attachments
Set myOlApp = Outlook.Application
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
For Each myItem In myInbox.Items
If myItem.Class = olMail Then
If myItem.Subject = "Payment Advice" Then
Set myAttachments = myItem.Attachments
For Each myAttachment In myAttachments
If Right(myAttachment.FileName, 4) = ".pdf" Then
' Open the PDF attachment and search for the keyword "Datascape"
Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim strText As String
strText = objFSO.OpenTextFile(myAttachment.Path).ReadAll
If InStr(strText, "Datascape") > 0 Then
myItem.Delete
End If
End If
End Sub
Sub ReadEmailsAndDelete()
Dim myOlApp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myItem As Object
Dim myAttachments As Outlook.Attachments
Set myOlApp = Outlook.Application
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
For Each myItem In myInbox.Items
If myItem.Class = olMail Then
If myItem.Subject = "Payment Advice" Then
Set myAttachments = myItem.Attachments
For Each myAttachment In myAttachments
If Right(myAttachment.FileName, 4) = ".pdf" Then
' Open the PDF attachment and search for the keyword "Datascape"
Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim strText As String
strText = objFSO.OpenTextFile(myAttachment.Path).ReadAll
If InStr(strText, "Datascape") > 0 Then
myItem.Delete
End If
End If
End Sub