Moving a .msg attachment to folder




I have the following code to detect a email that has a .msg attachment. I
want to move the .msg attachment into my inbox and delete the parent message.
I cannot move the attachment using the .move method. Can I redefine Atmt as
an object in or should I save the .msg and import it. I don't know how to do
either and I'd appriciate any assistance.

Sub MoveMSGAttachment()
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim varResponse As VbMsgBoxResult
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)

i = 0

For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
If Right(Atmt.FileName, 3) = "msg" Then
'FileName = "C:\temp\" & Atmt.FileName 'Not required
'Atmt.SaveAsFile FileName 'Not required

Atmt.Move Inbox ' *** PROBLEM CODE ***

i = i + 1
End If
Next Atmt
Next Item
End Sub

Thanks and regards

Phil (IncJourn)

Dmitry Streblechenko

You cannot move an embedded message (that's what MSG filee really) directly
using the Outlook Object Model.
You can save it first, then call Application.CreateItemFromTemplate
specifying the path to the MSG file. Just keep in mind that
CreateItemFromTemplate will strip out all the sender related properties; the
new message will be created in an unsent state in teh Drafts folder (you can
call MailItem.Move later to move it to a different fodler though).
<plug>You can use Redemption (url below) to import an MSG file - create a
new item in the target folder and just call

Dmitry Streblechenko (MVP)
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question