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

How to Add a MailItem to a Folder



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 10th 07, 07:37 PM posted to microsoft.public.outlook.program_vba
Ron
external usenet poster
 
Posts: 128
Default How to Add a MailItem to a Folder

I have created a folder called "Forwarded" and I am using this code:

Private Sub outApp_NewMailEx(ByVal EntryIDCollection As String)
' Dim oFolder As MAPIFolder
' Set oFolder = GetNamespace("MAPI").GetDefaultFolder(olFolderInbo x)
Dim arr() As String
Dim i As Integer
Dim m As MailItem
On Error Resume Next
arr = Split(EntryIDCollection, ",")
For i = 0 To UBound(arr)
Set m = Application.Session.GetItemFromID(arr(i))
m.To = "
AddNewItemToFolder (m)
m.Send


Next

End Sub


Public Sub AddNewItemToFolder(oItem As MailItem)
Dim oFolder As MAPIFolder
Set oFolder = GetNamespace("MAPI").Folders.Item("Forwarded")
oFolder.Items.Add (oItem)
End Sub

But Even though I have a breakpoint in AddNewItemToFolder, I never get
there. It's as if the call to this subroutine were commented out.
Ads
  #2  
Old January 10th 07, 09:35 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default How to Add a MailItem to a Folder

Firstly, do not try to send a message that has already been received. Create
a new message (Application.CreateItem or MAPIFolder.Items.Add), populate its
properties, then send,
Secondly. Items.Add create a brand new item and takes either an OlItemType
enum (e.g. olMailItem) or a string indicating teh desired message class
(e.g. "IPM.Note").
If you want to move an existing item to a folder, use MailItem.Move().

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

"RON" wrote in message
...
I have created a folder called "Forwarded" and I am using this code:

Private Sub outApp_NewMailEx(ByVal EntryIDCollection As String)
' Dim oFolder As MAPIFolder
' Set oFolder = GetNamespace("MAPI").GetDefaultFolder(olFolderInbo x)
Dim arr() As String
Dim i As Integer
Dim m As MailItem
On Error Resume Next
arr = Split(EntryIDCollection, ",")
For i = 0 To UBound(arr)
Set m = Application.Session.GetItemFromID(arr(i))
m.To = "
AddNewItemToFolder (m)
m.Send


Next

End Sub


Public Sub AddNewItemToFolder(oItem As MailItem)
Dim oFolder As MAPIFolder
Set oFolder = GetNamespace("MAPI").Folders.Item("Forwarded")
oFolder.Items.Add (oItem)
End Sub

But Even though I have a breakpoint in AddNewItemToFolder, I never get
there. It's as if the call to this subroutine were commented out.



  #3  
Old January 10th 07, 09:53 PM posted to microsoft.public.outlook.program_vba
Ron
external usenet poster
 
Posts: 128
Default How to Add a MailItem to a Folder

That worked! Thanks.

"Dmitry Streblechenko" wrote:

Firstly, do not try to send a message that has already been received. Create
a new message (Application.CreateItem or MAPIFolder.Items.Add), populate its
properties, then send,
Secondly. Items.Add create a brand new item and takes either an OlItemType
enum (e.g. olMailItem) or a string indicating teh desired message class
(e.g. "IPM.Note").
If you want to move an existing item to a folder, use MailItem.Move().

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

"RON" wrote in message
...
I have created a folder called "Forwarded" and I am using this code:

Private Sub outApp_NewMailEx(ByVal EntryIDCollection As String)
' Dim oFolder As MAPIFolder
' Set oFolder = GetNamespace("MAPI").GetDefaultFolder(olFolderInbo x)
Dim arr() As String
Dim i As Integer
Dim m As MailItem
On Error Resume Next
arr = Split(EntryIDCollection, ",")
For i = 0 To UBound(arr)
Set m = Application.Session.GetItemFromID(arr(i))
m.To = "
AddNewItemToFolder (m)
m.Send


Next

End Sub


Public Sub AddNewItemToFolder(oItem As MailItem)
Dim oFolder As MAPIFolder
Set oFolder = GetNamespace("MAPI").Folders.Item("Forwarded")
oFolder.Items.Add (oItem)
End Sub

But Even though I have a breakpoint in AddNewItemToFolder, I never get
there. It's as if the call to this subroutine were commented out.




 




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
add inline image to MailItem programmatically dragooon Outlook and VBA 1 September 27th 06 01:09 AM
Cannot add folder Mr Graham J Cook Outlook Express 1 September 15th 06 01:35 PM
Help - can't add "Item" (of type MailItem) using Attachments.Add() [email protected] Outlook and VBA 1 August 3rd 06 06:55 AM
MailItem Folder Path Fox via OfficeKB.com Outlook and VBA 1 July 7th 06 03:39 PM
How can I create a MailItem that displays like a received MailItem ? Clive Outlook - Using Forms 0 February 27th 06 05:14 PM


All times are GMT +1. The time now is 08:21 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-2025 Outlook Banter.
The comments are property of their posters.