Solved

vb move msg attachments and delete original emails

Posted on 2014-01-20
4
239 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 50

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

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

Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
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 …
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…

808 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