PDA

View Full Version : Solved: Outlook: Not providing attachments - Tough one



bassnsjp
02-21-2013, 06:50 PM
Dang it this the second time typing this in apparently the server was busy.

OS: Windows XP Outlook: 2003

I have a macro that upon selecting an Outlook folder will process each email in the folder and subfolder and save them out to a selected directory. The macro works very well, except for the condition I ran into today.

Scenario:
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 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) append did indeed have different data, but were not saved out.
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.

Any assistance would be greatly appreciated.


If (TypeName(MsgItem) <> "AppointmentItem") Then
Call ProcessEmail
If (TypeName(MsgItem) <> "NoteItem") Then
Set MsgAtt = MsgItem.Attachments
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

bassnsjp
02-21-2013, 06:53 PM
Is there any way to force Outlook to cycle through the attachments even if it appears they are copies. This script will be run on PST files that are provided to me so I have little control as to contents of the emails and their associated attachments. Thank you in advance for your time.

skatonni
02-22-2013, 06:15 AM
The attachments with the same name are overwritten.

See here for ways to generate unique names.

http://vbaexpress.com/forum/showthread.php?t=32499

bassnsjp
02-22-2013, 09:22 AM
Skateonni,

Thank you for your time and quick reply. However, I already address the condition of duplicate filenames. I accommodate it in a little different manner. See below. It appears that Outlook only cycles through for the unique filenames. Outlook detects copies internally and doesn't provide the attached copies to process. When I go back to work on Monday I will do a little more debugging to check how many cycles the "For" statement above is processed. This will be the definitive answer as to whether Outlook is only giving the unique names. If you have any other suggestions please fire away.

Thanks again for your time. By the way, can you tell me how to tag a thread as "Sovled", searched on the site and could not locate how with IE 9.


Do While 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
End If
Loop

skatonni
02-23-2013, 07:10 AM
Thanks again for your time. By the way, can you tell me how to tag a thread as "Sovled", searched on the site and could not locate how with IE 9.



Should be in "Thread Tools"

bassnsjp
02-25-2013, 02:16 PM
Skatonni,

I did some further testing this afternoon and noted that the "For" statement was in fact being processed the same number of times to match the attachment count.

The issue is/was that I did some code streamlining the other day and inadvertently moved the call to the filename validation function. This function removes extraneous blanks between the file extension and attachment filename as well as checking the attachment / subject title for invalid characters (* ? < > , etc.), and it also removes some terms we don't want used. Because of the misplaced function call I was checking for file existance with the original name vice the cleaned up filename, which is the name that is used to save the attachment. Therefore, the original filename would never be found, but when it would go to save out the file it was using the cleaned up version which would overwrite existing files. Like you said.

By the way, I integrated the method you referred to me above. It was a more efficient way of doing the same thing, thanks.

Thanks for your time and efforts.