Solved

vb move msg attachments and delete original emails

Posted on 2014-01-20
4
238 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 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39793949
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
ID: 39794077
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)
ID: 39796176
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
ID: 39799548
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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…
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

777 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