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 message from identified sender to another folder



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 2nd 09, 03:19 AM posted to microsoft.public.outlook.program_vba
jb
external usenet poster
 
Posts: 3
Default moving a message from identified sender to another folder

using outlook 2003

would anyone have a working snippet of code to move a message matching .SenderName to
a subfolder under Inbox ?

I have a subfolder under Inbox, called Messages from TheDomain

Each incoming message is now being processed so I already have the code working fine
in capturing sendername and subject, no questions about that part

when I identify a particular sender, would like to move this particular message from
Inbox

I'm thinking that it would look something like

if instr(msg.Sendername) = " then

Set objSentFolder = obInboxFolder.Parent.Folders("Messages from TheDomain")
Item.SaveSentMessageFolder objSentFolder

end if

Do I have to separately delete the inbox message or will .SaveSentMessageFolder take
care in such a way that only one message exists in one folder ?

this was the example on microsoft site (althought the example below does it by
strSubject, not Sender)

Private Sub objOL_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objDefFolder As Outlook.MAPIFolder
Dim objSentFolder As Outlook.MAPIFolder

Set objInboxFolder = Session.GetDefaultFolder(olFolderInbox)
Set objSentFolder = obInboxFolder.Parent.Folders("Sent Mail Archive")

Dim strSubject As String
Dim strLeft As String

strSubject = Item.Subject
strLeft = Left(strSubject, 3)
If strLeft = "" Then
Item.SaveSentMessageFolder objSentFolder
End If

Set objInboxFolder = Nothing
Set objSentFolder = Nothing
End Sub

Ads
  #2  
Old November 2nd 09, 01:08 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP][_4_]
external usenet poster
 
Posts: 552
Default moving a message from identified sender to another folder

You need to use a different approach. Changing the SaveSentMessageFolder
value would have an effect only on a message that has not yet been sent. For
your scenario, simply call the MailItem.Move method:

msg.Move objSentFolder
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"jb" wrote in message
m...
using outlook 2003

would anyone have a working snippet of code to move a message matching
.SenderName to a subfolder under Inbox ?

I have a subfolder under Inbox, called Messages from TheDomain

Each incoming message is now being processed so I already have the code
working fine in capturing sendername and subject, no questions about that
part

when I identify a particular sender, would like to move this particular
message from Inbox

I'm thinking that it would look something like

if instr(msg.Sendername) = " then

Set objSentFolder = obInboxFolder.Parent.Folders("Messages from
TheDomain")
Item.SaveSentMessageFolder objSentFolder

end if



  #3  
Old November 3rd 09, 12:59 PM posted to microsoft.public.outlook.program_vba
jb
external usenet poster
 
Posts: 3
Default moving a message from identified sender to another folder

your scenario, simply call the MailItem.Move method:

msg.Move objSentFolder


I must be missing something as that did not work, not sure if my objSentFolder is
defined wrong


  #4  
Old November 3rd 09, 01:12 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP][_4_]
external usenet poster
 
Posts: 552
Default moving a message from identified sender to another folder

What does "did not work" mean precisely? Errors? Other symptoms?

I don't have your earlier message. Please include the relevant code if you
post again.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"jb" wrote in message
...
your scenario, simply call the MailItem.Move method:

msg.Move objSentFolder


I must be missing something as that did not work, not sure if my
objSentFolder is defined wrong




  #5  
Old November 5th 09, 03:02 AM posted to microsoft.public.outlook.program_vba
jb
external usenet poster
 
Posts: 3
Default moving a message from identified sender to another folder

copy of original message

**
using outlook 2003

would anyone have a working snippet of code to move a message matching .SenderName to
a subfolder under Inbox ?

I have a subfolder under Inbox, called Messages from TheDomain

Each incoming message is now being processed so I already have the code working fine
in capturing sendername and subject, no questions about that part

when I identify a particular sender, would like to move this particular message from
Inbox

I'm thinking that it would look something like

if instr(msg.Sendername) = " then

Set objSentFolder = obInboxFolder.Parent.Folders("Messages from TheDomain")
Item.SaveSentMessageFolder objSentFolder

end if

Do I have to separately delete the inbox message or will .SaveSentMessageFolder take
care in such a way that only one message exists in one folder ?

this was the example on microsoft site (althought the example below does it by
strSubject, not Sender)

Private Sub objOL_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objDefFolder As Outlook.MAPIFolder
Dim objSentFolder As Outlook.MAPIFolder

Set objInboxFolder = Session.GetDefaultFolder(olFolderInbox)
Set objSentFolder = obInboxFolder.Parent.Folders("Sent Mail Archive")

Dim strSubject As String
Dim strLeft As String

strSubject = Item.Subject
strLeft = Left(strSubject, 3)
If strLeft = "" Then
Item.SaveSentMessageFolder objSentFolder
End If

Set objInboxFolder = Nothing
Set objSentFolder = Nothing
End Sub

  #6  
Old November 5th 09, 03:15 AM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP][_4_]
external usenet poster
 
Posts: 552
Default moving a message from identified sender to another folder

You still didn't say what isn't working, nor does the code you posted
include the changes I suggested. There's no point in reposting stale code.

But I did see two other things you should give some attention to:

1) SenderName won't necessarily contain an address. Use SenderEmailAddress
instead.

2) You should look up the syntax for Instr() in Help, because what you have
is not correct. It should be:

If Instr(msg.Sendername, ") 0 Then
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"jb" wrote in message
m...
copy of original message

**
using outlook 2003

would anyone have a working snippet of code to move a message matching
.SenderName to
a subfolder under Inbox ?

I have a subfolder under Inbox, called Messages from TheDomain

Each incoming message is now being processed so I already have the code
working fine
in capturing sendername and subject, no questions about that part

when I identify a particular sender, would like to move this particular
message from
Inbox

I'm thinking that it would look something like

if instr(msg.Sendername) = " then

Set objSentFolder = obInboxFolder.Parent.Folders("Messages from
TheDomain")
Item.SaveSentMessageFolder objSentFolder

end if

Do I have to separately delete the inbox message or will
.SaveSentMessageFolder take
care in such a way that only one message exists in one folder ?

this was the example on microsoft site (althought the example below does
it by
strSubject, not Sender)

Private Sub objOL_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objDefFolder As Outlook.MAPIFolder
Dim objSentFolder As Outlook.MAPIFolder

Set objInboxFolder = Session.GetDefaultFolder(olFolderInbox)
Set objSentFolder = obInboxFolder.Parent.Folders("Sent Mail Archive")

Dim strSubject As String
Dim strLeft As String

strSubject = Item.Subject
strLeft = Left(strSubject, 3)
If strLeft = "" Then
Item.SaveSentMessageFolder objSentFolder
End If

Set objInboxFolder = Nothing
Set objSentFolder = Nothing
End Sub



 




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
moving emails to folders based on sender email address Rudy L. Outlook and VBA 1 December 31st 08 12:14 PM
Journal entry fails after moving email message to folder RobM[_2_] Outlook - Using Contacts 0 December 18th 07 07:11 AM
moving message store folder Jeff Outlook Express 5 November 1st 07 12:01 AM
Copying/Moving/Saving an Embedded/Attached Message to a Mail Folder B Outlook and VBA 1 August 21st 07 07:46 PM
Membership in a Distribution List should be identified in Contact Philmont Fred Outlook - Using Contacts 4 February 2nd 06 03:16 PM


All times are GMT +1. The time now is 03: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.