Hello,
I am fairly new to VBA programming. I need to access emails from an Outlook subfolder. When I run the procedure, I get a Run Time error '440' array index out of bounds. Could someone explain what this error means and the steps needed to correct my vba code? Thanks
Sub DownloadEmailAttachment()
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFolder As Outlook.MAPIfolder
Dim olItem As Object
Dim mailitem As Outlook.mailitem
Dim olAtt As Outlook.Attachment
Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.Folders(olFolderInbox).Folders("CS Reports").Items
For Each olItem In olFolder.Items
If olItem.class = olMail Then
Set mailitem = olItem
Debug.Print mailitem.Subject
Debug.Print mailitem.ReceivedTime
End If
Next olItem
Set olFolder = Nothing
Set olNS = Nothing
Set olApp = Nothing
End Sub
I am fairly new to VBA programming. I need to access emails from an Outlook subfolder. When I run the procedure, I get a Run Time error '440' array index out of bounds. Could someone explain what this error means and the steps needed to correct my vba code? Thanks
Sub DownloadEmailAttachment()
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFolder As Outlook.MAPIfolder
Dim olItem As Object
Dim mailitem As Outlook.mailitem
Dim olAtt As Outlook.Attachment
Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.Folders(olFolderInbox).Folders("CS Reports").Items
For Each olItem In olFolder.Items
If olItem.class = olMail Then
Set mailitem = olItem
Debug.Print mailitem.Subject
Debug.Print mailitem.ReceivedTime
End If
Next olItem
Set olFolder = Nothing
Set olNS = Nothing
Set olApp = Nothing
End Sub