View Full Version : [SOLVED:] Loosing emails in InBox
jwise
05-26-2015, 12:14 PM
I'm having difficulty with a macro I wrote in 2008 under Office 2003. Now I'm using 2010, but it's worked for more than two years in 2010. Today it stopped. I found another macro I wrote which is much less complicated and it exhibits the same issue. The macro is supposed to read the InBox backwards and list the sender's name. This was a proof-of-concept macro which also fails now.
I have a lot more experience writing Excel macros, and I'm very inexperienced with Outlook.
My code always has "Option Explicit" but I've only included the relevant code. Since the emails are displayed in my InBox, it has to be I'm doing something wrong. In my particular case, the first five senders list as expected, but the next four emails senders are not listed.
Any help will be appreciated.
itemCT = Inbox.Items.count
msg = "ListSender- List of Sender Names of 20 E-mails" & vbCrLf
For j = itemCT To itemCT - 20 Step -1
msg = msg & Inbox.Items(j).SenderName & vbCrLf
Next j
MsgBox msg
The macro runs but does not get the first twenty email senders. It lists the first five correctly, then skips several emails (4), lists several more correctly, and skips a few more, continuing in this pattern. I've been unable to find anything unusual about the skipped emails. It skips the same emails every time. If I add emails to the InBox, the same ones are skipped.
Any ideas?
Thanks in advance
jwise
05-27-2015, 06:43 AM
I modified the above program to display the item number as well. Interestingly, there was no gap in the item numbers. The emails with attachments show in the "InBox", but they have apparently lost or never had an item number ("InBox.Items(j)" in the code). Clearly this is the wrong way to descend the InBox to find emails with attachments. Any ideas? The only thing I know different about the missing Item was that I replied to the email before I attempted to capture the attachment. Perhaps this puts it on another queue but leaves it in the InBox.
Thanks.
skatonni
05-27-2015, 02:16 PM
I suggest the question, as is, cannot be answered. Post the minimal amount of code to reproduce the problem.
Start with Option Explicit and end with End Sub.
jwise
05-27-2015, 04:43 PM
Thank you for your reply and interest.
Please remember this is not the "real code", but some test code I wrote before I developed the desired macro. Its purpose was to prove I was correctly reading the InBox. The other macro has several other features which are not germane to this issue.
The listed code has the exact same problem as my other code. I'll restate:
I'm reading the InBox by starting at the last email, and I read twenty emails back. I list the sender's name and item number. Although the item numbers are indeed consecutive, if I look at the standard view of the InBox I can see other emails that somehow are not listed by my macro.
I need to display all the emails that I see in my InBox because I'm looking for emails that have certain filetypes that have been attached. This part is in the other macro.
All emails as viewed in the standard pane are not listed by this macro.
Sub ListSenders()
'
' 03/27/08
'
Dim msg As String
Dim j As Integer
Dim itemCT As Integer
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
itemCT = Inbox.Items.count
msg = "ListSender- List of Sender Names of 20 E-mails" & vbCrLf
For j = itemCT To itemCT - 20 Step -1
msg = msg & Inbox.Items(j).SenderName & " Inbox " & j & vbCrLf
Next j
MsgBox msg
Set Inbox = Nothing
Set ns = Nothing
End Sub
I have used this code for several years, and I did verify that the "References" were made to Office 2010 and not 2003 where the code was originally developed.
Thanks
jwise
05-28-2015, 09:20 AM
I should also add:
1. I'm losing emails, not "loosing" them. I apologize to the Queen of England for misusing her language.
2. If you actually want to see the error, get someone to send you an email with an attachment. Reply to this email. Try the macro which should list the last 20 senders of emails to you. You will be missing the last email which you can clearly see in your InBox. I'm not sure if the attachment is actually required, but that's the way I tested it.
If you don't have twenty emails in your InBox, you'll need to adjust this number down to the correct amount. My emails are stored on my PC; if yours are stored on a server, I'm unsure of the results.
Thanks.
skatonni
05-28-2015, 11:43 AM
If you process the entire Inbox you may note the items are all listed but not in the expected order.
Try sorting.
Sub ListSenders_V2()
Dim msg As String
Dim j As Long
Dim itemCT As Long
Dim ns As Namespace
Dim Inbox As Folder '(post 2003)
Dim k As Long
Dim objFolderItems As Items
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set objFolderItems = Inbox.Items
itemCT = objFolderItems.count
Debug.Print itemCT
objFolderItems.sort "[ReceivedTime]", False
k = 0
For j = itemCT To itemCT - 10 Step -1
msg = msg & vbCrLf & objFolderItems(j).senderName
k = k + 1
Next j
msg = "ListSender- List of Sender Names of " & k & " E-mails in " & Inbox.Name & msg
MsgBox msg
Set ns = Nothing
Set Inbox = Nothing
Set objFolderItems = Nothing
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.