Solved

vb move msg attachments and delete original emails

Posted on 2014-01-20
4
235 Views
Last Modified: 2014-01-22
Please can somebody help me with a script that can process emails in a folder in Outlook 2010 (x64)

Any email found to have a .msg attachment, move the attachment to the folder and delete the original email.

Thanks
antonio
0
Comment
Question by:antonioking
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
Hi,

pls try

Sub SaveToFolder()


Dim olApp As Outlook.Application
Dim objNS As Outlook.Namespace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set myOlItems = objNS.GetDefaultFolder(olFolderInbox).Items
strSaveFolder = "Your Folder"


    For Each OlItem In myOlItems
    bMsgTrue = False
        If OlItem.Attachments.Count > 0 Then
            For Each ObjAttach In OlItem.Attachments
                If ObjAttach.Type = olEmbeddeditem Then
                    ObjAttach.SaveAsFile strSaveFolder & "\" & ObjAttach.DisplayName
                    Set objAtt = Nothing
                    bMsgTrue = True
                End If
            Next
            If bNMsg = True Then OlItem.Delete
        End If
    Next
        
End Sub

Open in new window

Regards
0
 

Author Comment

by:antonioking
Comment Utility
Hi, thanks for your help.
I actually wanted to save/copy/move the .msg attachments form the email to the same folder within Outlook. Not to a windows directory.

Regards
0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
Comment Utility
I think you need the Redemption addin object to read the .msg and save as an email....
http://www.dimastr.com/redemption/objects.htm

http://www.dimastr.com/redemption/objects.htm#SafeMailItem
Attachment : EmbeddedMsg property
Allows to access embedded message attachments. Returns MessageItem object. For regular (file) attachments this property is NULL
0
 

Author Closing Comment

by:antonioking
Comment Utility
Thanks for this
I saved the attachments to a windows folder then dragged and dropped.

Had to slightly modify the code as some email subjects contained characters windows won't let you name files with.

So here is my replaced code between lines 16-20

                i = i + 1
                If ObjAttach.Type = olEmbeddeditem Then
                    ObjAttach.SaveAsFile strSaveFolder & "\Email-" & i & ".msg"
                    Set objAtt = Nothing
                    bMsgTrue = True
                End If
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now