Please help me understand SaveAsFile for attachments

E

Ed from AZ

(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
 
S

Sue Mosher [MVP-Outlook]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top