I've been using some code that involves loops and it has been working fine every time but without changing the code I now run into a type mismatch error. Nothing in the code was change and my watches window shows the following:
I've condensed my code below: I'm really not sure why it worked 20+ times but now gives an error?
Expression | Value | Type | Context |
k | 11 | Integer | Sheet1.SendEmail |
olItems(k) | Variant/Object/ReportItem | Sheet1.SendEmail | |
olMail | [subject of email found] | MailItem/MailItem | Sheet1.SendEmail |
I've condensed my code below: I'm really not sure why it worked 20+ times but now gives an error?
VBA Code:
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim FlDr As MAPIFolder
Dim Subfldr As Outlook.Folder
Dim olMail As Outlook.MailItem
DIm olItems As Outlook.Items
Dim k As Integer
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace ("MAPI")
Set FlDr = olNs.GetDefaultFolder(olFolderIndex)
Set Subfldr = FlDr.Folders("Subfolder_name")
Set olItems = Subfldr.Items
olItems.Sort "[Received]", True
For k = 1 to olItems.Count
Set olMail = olItems(k) 'this is where I get the error