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
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
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…

728 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