Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vb move msg attachments and delete original emails

Posted on 2014-01-20
4
Medium Priority
?
268 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 53

Accepted Solution

by:
Rgonzo1971 earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Changing a few Outlook Options can help keep you organized!
This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

927 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