Solved

Need to modify VB script in Outlook that currently saves attachments to a folder, but want it to then delete email message

Posted on 2009-03-30
3
337 Views
Last Modified: 2012-05-06
Running Exchange2003 and Outlook2003.  I have a client-side rule that moves emails from a certain sender into a folder called "Faxes", then runs a script that saves the attachments that are on the emails into a folder.  This works great, however, I would like to modify the script to delete the entire email after it has saved the attachment.  Can anyone help?  

Here is the script:
Sub SaveAttachmentToFolder(Item As Outlook.MailItem)
    Dim olkAttachment As Outlook.Attachment, _
        intCounter As Integer
    For intCounter = Item.Attachments.Count To 1 Step -1
        Set olkAttachment = Item.Attachments.Item(intCounter)
        'Change the folder name and path as desired
        olkAttachment.SaveAsFile "C:\Faxes 2009\" & olkAttachment.FileName
    Next
    Set olkAttachment = Nothing
End Sub


Thanks!
0
Comment
Question by:redmanjb
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 250 total points
ID: 24024770
Hello redmanjb,



Regards,
Chris
Sub SaveAttachmentToFolder(Item As Outlook.MailItem)
    Dim olkAttachment As Outlook.Attachment, _
        intCounter As Integer
    For intCounter = Item.Attachments.Count To 1 Step -1
        Set olkAttachment = Item.Attachments.Item(intCounter)
        'Change the folder name and path as desired
        olkAttachment.SaveAsFile "C:\Faxes 2009\" & olkAttachment.FileName
    Next
    Set olkAttachment = Nothing
    item.delete
End Sub

Open in new window

0
 

Author Closing Comment

by:redmanjb
ID: 31564602
Yep, those two words did the trick!  Thank you very much for your prompt reply!  Cheers! :)
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24025024
Glad to help

Chris
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question