Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   Moving a .msg attachment to folder (http://www.outlookbanter.com/outlook-vba/24825-moving-msg-attachment-folder.html)

IncJourn August 23rd 06 01:02 PM

Moving a .msg attachment to folder
 
All,

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 ***
Item.Delete

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

Thanks and regards

Phil (IncJourn)


Dmitry Streblechenko August 23rd 06 06:55 PM

Moving a .msg attachment to folder
 
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).
plugYou can use Redemption (url below) to import an MSG file - create a
new item in the target folder and just call
SafeMailItem/RDOMail.Importplug

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"IncJourn" wrote in message
...
All,

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 ***
Item.Delete

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

Thanks and regards

Phil (IncJourn)





All times are GMT +1. The time now is 08:23 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com