View Single Post
  #1  
Old April 18th 08, 10:15 PM posted to microsoft.public.outlook.program_vba
Ed from AZ
external usenet poster
 
Posts: 6
Default Please help me understand SaveAsFile for attachments

D'oh!!!! 8\

Thank you, Sue. It now works great!!

Ed


On Apr 18, 12:59*pm, "Sue Mosher [MVP-Outlook]"
wrote:
The problem isn't with SaveAsFile but with your file name. A file name cannot include the / characters that you're adding with strDate. Windows interprets those as part of a file path which, of course, does not exist.

--
Sue Mosher, Outlook MVP
* *Author of Microsoft Outlook 2007 Programming:
* * *Jumpstart for Power Users and Administrators
* *http://www.outlookcode.com/article.aspx?id=54

"Ed from AZ" wrote in ...



(WinXPpro, OL2003) I have a PST folder full of emails with Word
documents as attachments. *I am trying to write a macro that will open
each of these emails and save the attachments to a folder as Word
docs. *I am fairly decent with Word and Excel VBA, but not very
familiar with Outlook VBA. *I found the SaveAsFile method, but I don't
quite understand how it works. *I'm trying to use it in the following
code, but it errors out:


x = objDestFolder.Items.Count
For cntI = 1 To x
*Set objItem = objDestFolder.Items(cntI)


*y = objItem.Attachments.Count
*For cntA = 1 To y
* *Set objAtt = objItem.Attachments(cntA)
* *strDoc = Left(objAtt.DisplayName, Len(objAtt.DisplayName) - 4)
* *strDate = Format(objItem.CreationTime, "mm/dd/yy")
* *strFile = strPath & strDoc & "_(" & strDate & ").doc"
* *objAtt.SaveAsFile strFile * ERROR HERE
*Next cntA
Next cntI


I can get to the folder, the email, and the attachment. *All strings
are fine. *The objAtt.SaveAsFile line, though, errors with
-209256445: Cannot save the attachment. Path does not exist. Make sure
the path is correct.


Any help setting this straight is appreciated.


Ed- Hide quoted text -


- Show quoted text -


Ads