Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXporting Excel Attachment File from Outlook to my personal folder? 1

Status
Not open for further replies.

tekvb1977

Technical User
Nov 16, 2005
46
US
I have to export an attachment from outlook e-mail to a folder on my drive. How could I accomplish it. I like this to be done automatically everynight. The attachment file name and name of the sender would stay the same.

Thanks a lot in advance.

J


 
Have a look at the Attachment.SaveAsFile method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I tried using the code below but it doesn't work. Any thoughts why it's not working?

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector.CurrentItem
Set myAttachments = myItem.Attachments
myAttachments.Item(1).SaveAsFile "C:\My Documents\" & _
myAttachments.Item(1).DisplayName

Thanks,

J
 
but it doesn't work
Any error message ? Unexpected behaviour ?
What is the value myAttachments.Item(1).DisplayName ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
It refers to name of the first attachment in the outlook e-mail. I get the following error everytime I try to run the sub procedure in outlook:

"The macros in this project are disabled. Please refer to the online help or documentation of the host application to determine how to enable macros."

I have no clue how to enable the macros. Any thoughts?

Thanks for all your help.

J
 
Check the macro security level in the Options menu of Outlook.

BTW, I asked for the value of the DisplayName property at error time, in case of invalid character for a file name ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for your help. Now I am getting the error that variable "myOlApp" is undefined:

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector.CurrentItem
Set myAttachments = myItem.Attachments
myAttachments.Item(1).SaveAsFile "C:\My Documents\" & _
myAttachments.Item(1).DisplayName


How can I define it? Like Dim myOlApp as Outlook?
 
The simplest:
Dim myOlApp, myItem, myAttachments

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks a bunch. Now the code works. But there is one problem. I have to open the e-mail before it running the code in order for it to work. Is there a way that an e-mail from a particular sender is opened first automatically before running the code below:


Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector.CurrentItem
Set myAttachments = myItem.Attachments
myAttachments.Item(1).SaveAsFile "C:\My Documents\" & _
myAttachments.Item(1).DisplayName
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top