moving a message from identified sender to another folder

Status
Not open for further replies.
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
 
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

"jb" <jb@cihj.nt> wrote in message

news:C9udnXq2rsg10nPXnZ2dnUVZ_gGdnZ2d@earthlink.com...
> 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
 
> 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
 
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

"jb" <jb@cihj.nt> wrote in message

news:GsydnfBxxvS-tG3XnZ2dnUVZ_qOdnZ2d@earthlink.com...
> > 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

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

Sue Mosher

"jb" <jb@cihj.nt> wrote in message

news:3e2dnYLdfvCr3W_XnZ2dnUVZ_v2dnZ2d@earthlink.com...
> 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
>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
L Moving Message Class email via script and Rule Outlook VBA and Custom Forms 3
A Outlook 2013 EAS: moving message causes duplicates Using Outlook 3
Commodore Message becomes "unread" after moving to a local folder Using Outlook 2
M Preventing conversation from moving to the top of the message box? Using Outlook 7
L check if send message appears in SendItems forder before moving Using Outlook 0
N Reply to Outlook messages by moving messages to a specific Outlook folder Outlook VBA and Custom Forms 1
P Moving from 2010 to 365 Using Outlook 3
O Moving "tasks" to inbox in Outlook 2016 Using Outlook 1
Abraham Outlook 2013 Lost my folders when moving from PST to IMAP Using Outlook 11
F Moving Outlook to new PC Using Outlook 0
R Moved 6 months worth (approx 1500 emails) lost from moving from TPG inbox to Icloud inbox (folders) Using Outlook 3
A Moving Public Folders to New Database Exchange Server Administration 3
R Problem moving file “Email folders.pst” to new PC Using Outlook 5
glnz Moving from Outlook 2003 to MS365 Outlook - need basics Using Outlook 4
E Having some trouble with a run-a-script rule (moving mail based on file type) Outlook VBA and Custom Forms 5
F Moving Contacts to New Profile Using Outlook 0
J Moving Imported folder Using Outlook 2
J Outlook 2016 Moving IMAP emails to Exchange Using Outlook 1
A .restrict results changing after moving to Exchange online Outlook VBA and Custom Forms 0
T I'm thinking about moving from outlook.com to the Outlook I have in my Office 365 Using Outlook 1
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
S Moving .OST file location unsuccessful! Using Outlook 6
M Moving mail to another folder is much slower than before (Office365) Using Outlook 0
D Any updates or fixes that would make this code stop working just moving emails to another folder Outlook VBA and Custom Forms 1
B Moving account, contacts & emails to another H/D with MSOutlook Using Outlook 5
M I'm Having problems Moving Contacts to a New List Using Outlook 8
D Moving Emails Based on Recipient/Sender Outlook VBA and Custom Forms 4
U Outlook 2010 'freezes' before moving emails Using Outlook 2
S Moving Emails Between Archive Folders Using Outlook 1
P Moving Outlook.pst & archive1.pst Using Outlook 3
A Moving archived contents in Outlook 2007 back into working folders Using Outlook 0
Diane Poremsky Moving Deleted Items Using Outlook 0
O Moving .ost file Using Outlook 12
Diane Poremsky Outlook.com is moving to Office 365! Using Outlook 3
Diane Poremsky Check Contacts before moving them to Hotmail Contacts folder Using Outlook 0
V Problem moving folders Using Outlook 4
Diane Poremsky Moving Outlook to a New Computer Using Outlook 0
Diane Poremsky Moving from Outlook Express to Outlook Using Outlook 0
M1ck53 Moving Outlook Using Outlook 9
Diane Poremsky Moving an Outlook offline data file (*.ost) Using Outlook 3
D After Moving or Deleting Open Item - Meeting Requests Using Outlook 4
E Moving autoarchive settings to new computer (Outlook 2007) Using Outlook 1
Nick Truscott Lost custom forms after moving mailbox Outlook VBA and Custom Forms 3
R Moving contacts from ICloud back to Outlook 2010 Using Outlook 4
M which Outlook recommended to buy for moving Outlook 2000 versions Contact Data Using Outlook 2
P Moving PST file questions Using Outlook 3
Klaas "To Address" duplicated when moving msg to another folder Using Outlook 2
C Moving BCM Database to Server Share BCM (Business Contact Manager) 1
A Moving .msg files back into outlook Using Outlook 2
S automatically moving flagged sent e-mail to a special folder Outlook VBA and Custom Forms 1

Similar threads

Back
Top