moving a message from identified sender to another folder

J

jb

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) = "@thedomain.com" 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 = "RE:" Then
Item.SaveSentMessageFolder objSentFolder
End If

Set objInboxFolder = Nothing
Set objSentFolder = Nothing
End Sub
 
S

Sue Mosher [MVP]

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
 
J

jb

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
 
S

Sue Mosher [MVP]

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.
 
J

jb

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) = "@thedomain.com" 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 = "RE:" Then
Item.SaveSentMessageFolder objSentFolder
End If

Set objInboxFolder = Nothing
Set objSentFolder = Nothing
End Sub
 
S

Sue Mosher [MVP]

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, "@thedomain.com") > 0 Then
 

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

Top