A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Moving a .msg attachment to folder



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old August 23rd 06, 01:02 PM posted to microsoft.public.outlook.program_vba
IncJourn
external usenet poster
 
Posts: 1
Default 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)

Ads
  #2  
Old August 23rd 06, 06:55 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default 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)



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I see the full line of a msg (inbox), without moving side Singa Outlook - General Queries 1 July 11th 06 04:00 PM
Moving Folder Denis R Charron Outlook - General Queries 0 June 27th 06 06:33 PM
Drag msg to explorer folder - change name? ben ik Outlook - General Queries 1 April 13th 06 12:20 AM
"Unable to Display the Folder" msg, can't delete folder Yvonne Outlook - Calandaring 2 March 29th 06 09:01 PM
How to copy attachment .msg into folder ? [email protected] Outlook and VBA 2 February 22nd 06 02:17 PM


All times are GMT +1. The time now is 08:36 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.