Outlook Cannot access more than the Outlook VBA 250 Mail Items


Joined
Aug 23, 2016
Messages
2
Reaction score
0
Hi all,

I am sure this has been discussed in great lengths, but I do not have access to change the registry of the Exchange Server. I cannot seem to figure out how to search through an Inbox with more than 250 items. Is there a way to close each item or do a similar action to Marshal.ReleaseComObjects

Below is my code. Thank you in advance.

On Error GoTo GetAttachments_err
' Declare variables
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
i = 0
' Check Inbox for messages and exit of none found
If Inbox.Items.Count = 0 Then
MsgBox "There are no operating statements in the Inbox.", vbInformation, _
"Nothing Found"
Exit Sub
End If
' Check each message for attachments
For Each Item In Inbox.Items
' Save any attachments found
For Each Atmt In Item.Attachments
If Right(Atmt.FileName, 4) = "xlsx" And InStr(1, Item.Subject, "operating") > 0 Then
'And InStr(Atmt.FileName, "operating") And Atmt.Type <> 5 Then
' This path must exist! Change folder name as necessary.
FileName = "C:\EmailAttachments\" & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
End If
Next Atmt

Next Item


If i > 0 Then
MsgBox "I found " & i & " operating statements attached." _
& vbCrLf & "I have saved them into the C:\EmailAttachments folder." _
& vbCrLf & vbCrLf & "", vbInformation, "Finished!"
Else
MsgBox "I didn't find any attached files in your mail.", vbInformation, "Finished!"
End If
' Clear memory
GetAttachments_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Exit Sub

' Handle errors
GetAttachments_err:
' If Err.Description = "Outlook cannot perform this action on this type of attachment." Then
' Err.Clear
' Resume nonValidAttachment
' End If


MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: GetAttachments" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume GetAttachments_exit
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top