VBA code for moving attachment

  • Thread starter Thread starter R. Elorza
  • Start date Start date
R

R. Elorza

Hi.
I have some experience with VBA macros in Excel but none in Outlook
I need some code lines to move or copy an attachment to a given system
folder.
The code would be called by a rule. This part I have already sorted out.
Thanks in advance
R
 
Hi.
I have some experience with VBA macros in Excel but none in Outlook
I need some code lines to move or copy an attachment to a given system
folder.
The code would be called by a rule. This part I have already sorted out.
Thanks in advance
R

Version is Outlook 2002
 
These samples show a couple of different ways to save attachments:

http://www.outlookcode.com/codedetail.aspx?id=70
http://www.slovaktech.com/code_samples.htm#StripAttachments

To call a VBA macro from a 'run a script' rule, the macro needs to be in
this format, where MailItem is the item passed by the rule:

Sub DoStuff(MyItem as MailItem)
' do stuff to MyItem
End Sub
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Sue, you are incredible!!
Just what I needed.
I got it up and working in 15 minutes.
Thaks very, very much
R
 
Hi! Here is a Macro could save all Attachments in outlook's inbox to
harddisk.Sorry I am Chinese,my english is poor.

Here is the code maybe is you want. Please reference "Microsoft Outlook
application library" before run it.

Sub SaveOutlookAtt()

On Error Resume Next

Dim myolapp As New Outlook.Application

Set fs = CreateObject("Scripting.FileSystemObject")

If Not fs.FolderExists("c:\MailAtt") Then fs.CreateFolder ("c:\MailAtt")
'make a folder to store the attachments

Set myNameSpace = myolapp.GetNamespace("MAPI")
Set myfolder = myNameSpace.GetDefaultFolder(olFolderInbox)

For i = 1 To myfolder.Items.Count

Set mymailitem = myfolder.Items(i)

With mymailitem

Set myAttachments = mymailitem.Attachments

para = myAttachments.Item(1).DisplayName

myAttachments.Item(1).SaveAsFile "c:\MailAtt" +
IIf(IsNull(myAttachments.Item(1).DisplayName),
i,myAttachments.Item(1).DisplayName)

End With
Next

MsgBox "All Attachments has been Save to the c:\MailAtt folder",
vbDefaultButton1, "Program by Loadhigh"

End Sub
 
Back
Top