I have VBA code in Outlook 2016 Pro Plus that has run for years.
All of a sudden, almost every time I do a Send & Receive I am getting an error on Set myEmail =.
Option Explicit
Option Base 1
Option Compare Text
Sub MyRules()
Set myNameSpace = GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
myEmails = myInbox.Items.Count
For myCount = myEmails To 1 Step -1
Set myEmail = myInbox.Items(myCount) '**<<< Error occurs on this line <<<**
Select Case myEmail.SenderEmailAddress
Case Is = "aaa@gmail.com", "bbb@btinternet.com", "ccc@gmail.com"
mySender = "Cxxxxx Dxxxxxx"
Case Else
mySender = myEmail.SenderEmailAddress
End Select
Select Case mySender
Case Is = ""
If myEmail.Subject = "" Then
myEmail.UnRead = False
myEmail.Delete
GoTo Next_EMail
End If
This should be all of the relevant DIM statements.
Public myNameSpace As NameSpace
Public myInbox As MAPIFolder
Public myDest As MAPIFolder
Public myEmail As MailItem
Public myEmails As Integer
Public myCount As Integer
Public myAtmt As Attachment
Public myAtmtNo As Integer
Public mySender As String
Public myRecip As Outlook.Recipient
Public mySubFolders As Outlook.Folders
Public mySubFolder As MAPIFolder
Public mySubFolder1 As MAPIFolder
Public mySubFolder2 As MAPIFolder
Public mySubFolder3 As MAPIFolder
Public myNS As NameSpace
Public myTestFolder As Outlook.Folder
Public myFoldersArray As Variant
Public myLoopIndex As Integer
Public myOlApp As Outlook.Application
Public myOlTsk As TaskItem
Public myNoOfEMails As Long
