PDA

View Full Version : Solved: OUTLOOK SaveAsFile Corruption



gmaxey
09-20-2012, 03:07 AM
I have some simple code that saves an OUTLOOK attachment (Word 2010 document with content controls) to a file.

For lngTmp = 1 To olAttachments.Count
strAttachment_FileName = strTempFolderPath & Application.PathSeparator & olAttachments.Item(lngTmp).DisplayName
If fcnCheckAttachments(strAttachment_FileName) = True Then
'Save the attachment to the temporary folder
olAttachments.Item(1).SaveAsFile strAttachment_FileName
bAttachmentSaved = True
Exit For
End If
Next lngTmp
If Not bAttachmentSaved Then
'The attachment was not found
olItem.UnRead = True
olItem.Move olFolder.Folders("Invalid Forms")
GoTo ProcessNext
End If

When the process runs, the resulting file is corrupt and can no longer be opened in Word.

I can open the attachment while in OUTLOOK, I can save the attachment manually and then open it, but if I use the SaveAsFile method, I can not longer open the file.

Cross posted: http://answers.microsoft.com/en-us/office/forum/office_2010-customize/olattachmentsitem1saveasfile-results-in-corrupted/f992866b-3775-482f-be5d-42c1a7534df8
Any ideas? Thanks,

BrianMH
09-20-2012, 03:45 AM
Shouldn't it be as below. Your currently looking at the first attachment which may or not be a word file which is why it may be corrupting.

olAttachments.Item(lngTmp).SaveAsFile strAttachment_FileName

gmaxey
09-20-2012, 03:52 AM
Brian,

Of course. I fell like and idiot. I'm sitting here around a pile of hair clumps and bloody scalp, because I couldn't see the tree for the forrest. Thank you!!

BrianMH
09-20-2012, 04:40 AM
Happens to us all more often than I would like to admit!