none
Outlook only process unique embedded emails that are attachments RRS feed

  • Question

  • I have a vba macro that upon selecting an Outlook folder will process each email and save them out to a selected directory. The macro works very well, except for the condition I just encountered.

    Scenario:

    OS: Windows XP    and   Outlook 2008

    A particular email has 15 attachments it just so happens they are all embedded emails. Not a problem the marco deals with them normally with no problems. Also, MsgItem.Attachments.Count returns the correct count of 15. However, of the 15 embedded emails 7 of them have the EXACT same title as several of the other embedded emails. To deal with this Outlook appends (1), (2), (3), etc to the attached copies to make the titles UNIQUE.

    Issue:

    When I cycle through the number of attachments Outlook ONLY provides me with the 8 unique attachments and does not process the rest. Therefore, the output directory only contains 8 of the 15 files. This might not be an issue however, the 7 embedded emails that appear to be EXACT copies because of the title actually contain different content. I found this out by comparing the files that were saved out with the actual attachments in the email. All emails with (1), (2), etc appended did indeed have different data, but were not saved out.  Anyone have any idea how to force Outlook to provide the 7 embedded emails so they can be processed?  Appreciate any assistance, thank you in advance.

    The code is on my PC at work that is not connected to the internet. However, a small snipet of the code that cycles through the attachments is included below. Additionally, I provided another small snipet of code that checks for duplicates of filenames and if one is found it increments the attachment identifier (AttID).

        If (TypeName(MsgItem) <> "AppointmentItem") Then
            Call ProcessEmail
            If (TypeName(MsgItem) <> "NoteItem") Then
                Set MsgAtt = MsgItem.Attachments   ' this is it
                For iatt = Attmcnt To 1 Step -1
                    Call ProcessAttachment
                Next
            End If
        Else
            CalErrMsg.Show
            ExitProc = True
            FSOLogFile.Writeline String(50, "*") & "    Appointment Mail Item encountered.  Please delete calendars and rerun script    " & String(50, "*")
            Call ExitProcedure
            Exit Sub
        End If

    DoWhile ContLoop = True
    If Dir(filepath & AttFilename2) = "" Then
            ContLoop = False
    Else
            AttID = AttID + 1
            AttstrID = Format(AttID, "00")
            AttFilename2 = AttFilename1 & "_" & AttstrID & "_" & MsgAtt.Item(iatt).filename
            ContLoop = True
    EndIf
    Loop

    [/vba]

                        


    • Edited by bassnsjp Sunday, February 24, 2013 4:43 PM
    Saturday, February 23, 2013 10:23 PM

Answers

  • Ok, what you can't see is the egg on my face.

    Several days before the above problem started to appear I did some slight changes to streamline the code. It just so happens that I moved a call to the Function that validated the filename by removing certain characters and extraneous blanks between the extension and the attachment name.  As such, the name of the original attachment was being tested to see if it existed and then the validate function would process and the results was used to save the attachment out.  Therefore, neither of the two filenames would be the same however,  the final filename did match files that already existed, but the test for file existance already occurred thus, the files would be overwritten. 

    I apologize for everyone wasting their time reviewing and investigating this issue. Your time could have been better spent elsewhere.

    • Marked as answer by bassnsjp Monday, February 25, 2013 8:49 PM
    Monday, February 25, 2013 8:49 PM

All replies

  • So if you give each attachment a unique name, how is it possible that you only end up with 8 attachments instead of 15? Do you get an error when you call Attachment.saveAsFile? Is Attachments.Count wrong?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Sunday, February 24, 2013 9:34 PM
  • Dmitry,

    Thank you for your time and response.  That is the quandary at hand. The Attachments.count is not wrong, there are indeed 15 embedded emails.   The email attachment extraction process completes with no errors.  The only thing is that 7 of the files are missing from that one email.  Tomorrow I will debug.print the attachment number and itss associated title before calling ProcessAttachment.  This will give me a little bit more information to work with and will let me know if the "For" statement is being processed all 15 times or is it being fed only 8 of the 15.  I was hoping that someone had encountered this and would have a method to access the other 7 embedded emails.

    Steve

    • Marked as answer by bassnsjp Monday, February 25, 2013 8:35 PM
    • Unmarked as answer by bassnsjp Monday, February 25, 2013 8:35 PM
    Monday, February 25, 2013 2:27 AM
  • Ok, what you can't see is the egg on my face.

    Several days before the above problem started to appear I did some slight changes to streamline the code. It just so happens that I moved a call to the Function that validated the filename by removing certain characters and extraneous blanks between the extension and the attachment name.  As such, the name of the original attachment was being tested to see if it existed and then the validate function would process and the results was used to save the attachment out.  Therefore, neither of the two filenames would be the same however,  the final filename did match files that already existed, but the test for file existance already occurred thus, the files would be overwritten. 

    I apologize for everyone wasting their time reviewing and investigating this issue. Your time could have been better spent elsewhere.

    • Marked as answer by bassnsjp Monday, February 25, 2013 8:49 PM
    Monday, February 25, 2013 8:49 PM