move read email based on date and sender

Status
Not open for further replies.
V

vbaNEWBIE

Hopefully someone here can help....I would like to move items from my inbox

based on a specific situation. I have the code below for part of it but I

need to add more code to complete it. I am using Outlook 2007 and the code

will run from a Module when initiated by the User.

I would like to move items if meets ALL three conditions:

(1) comes from the Sendername coded below - AND -

(2) the email has been READ - AND -

(3) and the sent date is 14 days old or older

Can anyone help me understand how to modify the code below to accomplish

this ?

Sub MoveItems_Inbox()

Dim myOlApp As New Outlook.Application

Dim myNameSpace As Outlook.NameSpace

Dim myInbox As Outlook.MAPIFolder

Dim myDestFolder As Outlook.MAPIFolder

Dim myItems As Outlook.Items

Dim myItem As Object

Set myNameSpace = myOlApp.GetNamespace("MAPI")

Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)

Set myItems = myInbox.Items

Set myDestFolder =

Outlook.Session.Folders("PersonalFolder").Folders("PersonNameFolder")

Set myItem = myItems.Find("[SenderName] = 'PersonName'")

While TypeName(myItem) <> "Nothing"

myItem.Move myDestFolder

Set myItem = myItems.FindNext

Wend

End Sub
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Modify the filter like this: [SenderName] = 'x' AND [Unread] = 'false' AND

[SentOn] <= '...'

Please see the VBA help for how to use a date with the Find function.

Best regards

Michael Bauer

Am Tue, 16 Feb 2010 08:45:01 -0800 schrieb vbaNEWBIE:


> Hopefully someone here can help....I would like to move items from my


inbox
> based on a specific situation. I have the code below for part of it but I
> need to add more code to complete it. I am using Outlook 2007 and the


code
> will run from a Module when initiated by the User.

> I would like to move items if meets ALL three conditions:
> (1) comes from the Sendername coded below - AND -
> (2) the email has been READ - AND -
> (3) and the sent date is 14 days old or older

> Can anyone help me understand how to modify the code below to accomplish
> this ?

> Sub MoveItems_Inbox()
> Dim myOlApp As New Outlook.Application
> Dim myNameSpace As Outlook.NameSpace
> Dim myInbox As Outlook.MAPIFolder
> Dim myDestFolder As Outlook.MAPIFolder
> Dim myItems As Outlook.Items
> Dim myItem As Object
> Set myNameSpace = myOlApp.GetNamespace("MAPI")
> Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
> Set myItems = myInbox.Items

> Set myDestFolder =
> Outlook.Session.Folders("PersonalFolder").Folders("PersonNameFolder")
> Set myItem = myItems.Find("[SenderName] = 'PersonName'")
> While TypeName(myItem) <> "Nothing"
> myItem.Move myDestFolder
> Set myItem = myItems.FindNext
> Wend
> End Sub
 
V

vbaNEWBIE

Thanks Michael - so that I understand I would change it to the following:

Set myItem = myItems.Find("[SenderName] = 'PersonName' AND [Unread] =

'false' AND [SentOn] <= 'DateToMove'")

Did I move the quotation marks correctly ?

Will have to search on using a Date with a Find function.

thanks !

"Michael Bauer " wrote:



> Modify the filter like this: [SenderName] = 'x' AND [Unread] = 'false' AND
> [SentOn] <= '...'

> Please see the VBA help for how to use a date with the Find function.

> > Best regards
> Michael Bauer
>

>

> Am Tue, 16 Feb 2010 08:45:01 -0800 schrieb vbaNEWBIE:
>
> > Hopefully someone here can help....I would like to move items from my

> inbox
> > based on a specific situation. I have the code below for part of it but I
> > need to add more code to complete it. I am using Outlook 2007 and the

> code
> > will run from a Module when initiated by the User.
> > I would like to move items if meets ALL three conditions:
> > (1) comes from the Sendername coded below - AND -
> > (2) the email has been READ - AND -
> > (3) and the sent date is 14 days old or older
> > Can anyone help me understand how to modify the code below to accomplish
> > this ?
> > Sub MoveItems_Inbox()
> > Dim myOlApp As New Outlook.Application
> > Dim myNameSpace As Outlook.NameSpace
> > Dim myInbox As Outlook.MAPIFolder
> > Dim myDestFolder As Outlook.MAPIFolder
> > Dim myItems As Outlook.Items
> > Dim myItem As Object
> > Set myNameSpace = myOlApp.GetNamespace("MAPI")
> > Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
> > Set myItems = myInbox.Items
> > Set myDestFolder =
> > Outlook.Session.Folders("PersonalFolder").Folders("PersonNameFolder")
> > Set myItem = myItems.Find("[SenderName] = 'PersonName'")
> > While TypeName(myItem) <> "Nothing"
> > myItem.Move myDestFolder
> > Set myItem = myItems.FindNext
> > Wend
> > End Sub

> .
>
 
V

vbaNEWBIE

Another thought on the Date issue.....is there a way to utilize the Date

function in the filter so that you could use something like If DateReceived <

(Date - 14) Then move to another folder ?

I have used the (Date - 14) within VBA for Excel and it works great and if

this would work it would allow for basically a variable to be used rather

than a specific date. This would be helpful if someone wanted to regularly

run the macro to move emails older than 14 days without having to code it

differently each time.

Thoughts ?

"Michael Bauer " wrote:



> Modify the filter like this: [SenderName] = 'x' AND [Unread] = 'false' AND
> [SentOn] <= '...'

> Please see the VBA help for how to use a date with the Find function.

> > Best regards
> Michael Bauer
>

>

> Am Tue, 16 Feb 2010 08:45:01 -0800 schrieb vbaNEWBIE:
>
> > Hopefully someone here can help....I would like to move items from my

> inbox
> > based on a specific situation. I have the code below for part of it but I
> > need to add more code to complete it. I am using Outlook 2007 and the

> code
> > will run from a Module when initiated by the User.
> > I would like to move items if meets ALL three conditions:
> > (1) comes from the Sendername coded below - AND -
> > (2) the email has been READ - AND -
> > (3) and the sent date is 14 days old or older
> > Can anyone help me understand how to modify the code below to accomplish
> > this ?
> > Sub MoveItems_Inbox()
> > Dim myOlApp As New Outlook.Application
> > Dim myNameSpace As Outlook.NameSpace
> > Dim myInbox As Outlook.MAPIFolder
> > Dim myDestFolder As Outlook.MAPIFolder
> > Dim myItems As Outlook.Items
> > Dim myItem As Object
> > Set myNameSpace = myOlApp.GetNamespace("MAPI")
> > Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
> > Set myItems = myInbox.Items
> > Set myDestFolder =
> > Outlook.Session.Folders("PersonalFolder").Folders("PersonNameFolder")
> > Set myItem = myItems.Find("[SenderName] = 'PersonName'")
> > While TypeName(myItem) <> "Nothing"
> > myItem.Move myDestFolder
> > Set myItem = myItems.FindNext
> > Wend
> > End Sub

> .
>
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
If the filter isn't as flexible as you need it for the date, filter the

items just for SenderName and Unread. Then loop through the result, read

each item's SentOn property, and do your calculation with it.

Best regards

Michael Bauer

Am Wed, 17 Feb 2010 06:22:02 -0800 schrieb vbaNEWBIE:


> Another thought on the Date issue.....is there a way to utilize the Date
> function in the filter so that you could use something like If


DateReceived <
> (Date - 14) Then move to another folder ?

> I have used the (Date - 14) within VBA for Excel and it works great and if
> this would work it would allow for basically a variable to be used rather
> than a specific date. This would be helpful if someone wanted to


regularly
> run the macro to move emails older than 14 days without having to code it
> differently each time.

> Thoughts ?

> "Michael Bauer " wrote:
>
>

>
>> Modify the filter like this: [SenderName] = 'x' AND [Unread] = 'false'


AND
> > [SentOn] <= '...'
>

>> Please see the VBA help for how to use a date with the Find function.
>

>> > > Best regards
> > Michael Bauer
> >

> >

>
>
>> Am Tue, 16 Feb 2010 08:45:01 -0800 schrieb vbaNEWBIE:
> >
> >> Hopefully someone here can help....I would like to move items from my

> > inbox
> >> based on a specific situation. I have the code below for part of it but


I
> >> need to add more code to complete it. I am using Outlook 2007 and the

> > code
> >> will run from a Module when initiated by the User.
> >
>>
>>> I would like to move items if meets ALL three conditions:
> >> (1) comes from the Sendername coded below - AND -
> >> (2) the email has been READ - AND -
> >> (3) and the sent date is 14 days old or older
> >
>>
>>
>>> Can anyone help me understand how to modify the code below to accomplish
> >> this ?
> >
>>
>>> Sub MoveItems_Inbox()
> >> Dim myOlApp As New Outlook.Application
> >> Dim myNameSpace As Outlook.NameSpace
> >> Dim myInbox As Outlook.MAPIFolder
> >> Dim myDestFolder As Outlook.MAPIFolder
> >> Dim myItems As Outlook.Items
> >> Dim myItem As Object
> >> Set myNameSpace = myOlApp.GetNamespace("MAPI")
> >> Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
> >> Set myItems = myInbox.Items
> >
>>> Set myDestFolder =
> >> Outlook.Session.Folders("PersonalFolder").Folders("PersonNameFolder")
> >> Set myItem = myItems.Find("[SenderName] = 'PersonName'")
> >> While TypeName(myItem) <> "Nothing"
> >> myItem.Move myDestFolder
> >> Set myItem = myItems.FindNext
> >> Wend
> >> End Sub

> > .
> >
 
V

vbaNEWBIE

hhhmmmm.....thanks Michael.......what would the code look like for that ? I

am new to VBA with Outlook so I do not have my legs under me yet.

Any suggestions ?

"Michael Bauer " wrote:



> If the filter isn't as flexible as you need it for the date, filter the
> items just for SenderName and Unread. Then loop through the result, read
> each item's SentOn property, and do your calculation with it.

> > Best regards
> Michael Bauer
>

>

> Am Wed, 17 Feb 2010 06:22:02 -0800 schrieb vbaNEWBIE:
>
> > Another thought on the Date issue.....is there a way to utilize the Date
> > function in the filter so that you could use something like If

> DateReceived <
> > (Date - 14) Then move to another folder ?
> > I have used the (Date - 14) within VBA for Excel and it works great and if
> > this would work it would allow for basically a variable to be used rather
> > than a specific date. This would be helpful if someone wanted to

> regularly
> > run the macro to move emails older than 14 days without having to code it
> > differently each time.
> > Thoughts ?
> > "Michael Bauer " wrote:
> >
> >
> >
> >> Modify the filter like this: [SenderName] = 'x' AND [Unread] = 'false'

> AND
> >> [SentOn] <= '...'
> >
> >> Please see the VBA help for how to use a date with the Find function.
> >
> >> > >> Best regards
> >> Michael Bauer
> >>

> >>

> >
> >
> >> Am Tue, 16 Feb 2010 08:45:01 -0800 schrieb vbaNEWBIE:
> >
> >>> Hopefully someone here can help....I would like to move items from my
> >> inbox
> >>> based on a specific situation. I have the code below for part of it but

> I
> >>> need to add more code to complete it. I am using Outlook 2007 and the
> >> code
> >>> will run from a Module when initiated by the User.
> >>
> >>
> >>> I would like to move items if meets ALL three conditions:
> >>> (1) comes from the Sendername coded below - AND -
> >>> (2) the email has been READ - AND -
> >>> (3) and the sent date is 14 days old or older
> >>
> >>
> >>
> >>> Can anyone help me understand how to modify the code below to accomplish
> >>> this ?
> >>
> >>
> >>> Sub MoveItems_Inbox()
> >>> Dim myOlApp As New Outlook.Application
> >>> Dim myNameSpace As Outlook.NameSpace
> >>> Dim myInbox As Outlook.MAPIFolder
> >>> Dim myDestFolder As Outlook.MAPIFolder
> >>> Dim myItems As Outlook.Items
> >>> Dim myItem As Object
> >>> Set myNameSpace = myOlApp.GetNamespace("MAPI")
> >>> Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
> >>> Set myItems = myInbox.Items
> >>
> >>> Set myDestFolder =
> >>> Outlook.Session.Folders("PersonalFolder").Folders("PersonNameFolder")
> >>> Set myItem = myItems.Find("[SenderName] = 'PersonName'")
> >>> While TypeName(myItem) <> "Nothing"
> >>> myItem.Move myDestFolder
> >>> Set myItem = myItems.FindNext
> >>> Wend
> >>> End Sub
> >> .
> >>

> .
>
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Date functions in Outlook are the same as in Excel.

Best regards

Michael Bauer

Am Wed, 17 Feb 2010 13:15:01 -0800 schrieb vbaNEWBIE:


> hhhmmmm.....thanks Michael.......what would the code look like for that ?


I
> am new to VBA with Outlook so I do not have my legs under me yet.

> Any suggestions ?

> "Michael Bauer " wrote:
>
>

>
>> If the filter isn't as flexible as you need it for the date, filter the
> > items just for SenderName and Unread. Then loop through the result, read
> > each item's SentOn property, and do your calculation with it.
>

>> > > Best regards
> > Michael Bauer
> >

> >

>
>
>> Am Wed, 17 Feb 2010 06:22:02 -0800 schrieb vbaNEWBIE:
> >
> >> Another thought on the Date issue.....is there a way to utilize the Date
> >> function in the filter so that you could use something like If

> > DateReceived <
> >> (Date - 14) Then move to another folder ?
> >
>>> I have used the (Date - 14) within VBA for Excel and it works great and


if
> >> this would work it would allow for basically a variable to be used


rather
> >> than a specific date. This would be helpful if someone wanted to

> > regularly
> >> run the macro to move emails older than 14 days without having to code


it
> >> differently each time.
> >
>>> Thoughts ?
> >
>>> "Michael Bauer " wrote:
> >
>>>
>>>
>>>> Modify the filter like this: [SenderName] = 'x' AND [Unread] = 'false'

> > AND
> >>> [SentOn] <= '...'
> >>
>>>> Please see the VBA help for how to use a date with the Find function.
> >>
>>>> > >>> Best regards
> >>> Michael Bauer
> >>>

> >>>

>>>
>>>
>>>> Am Tue, 16 Feb 2010 08:45:01 -0800 schrieb vbaNEWBIE:
> >>
>>>>> Hopefully someone here can help....I would like to move items from my
> >>> inbox
> >>>> based on a specific situation. I have the code below for part of it


but
> > I
> >>>> need to add more code to complete it. I am using Outlook 2007 and the
> >>> code
> >>>> will run from a Module when initiated by the User.
> >>>
>>>>
>>>>> I would like to move items if meets ALL three conditions:
> >>>> (1) comes from the Sendername coded below - AND -
> >>>> (2) the email has been READ - AND -
> >>>> (3) and the sent date is 14 days old or older
> >>>
>>>>
>>>>
>>>>> Can anyone help me understand how to modify the code below to


accomplish
> >>>> this ?
> >>>
>>>>
>>>>> Sub MoveItems_Inbox()
> >>>> Dim myOlApp As New Outlook.Application
> >>>> Dim myNameSpace As Outlook.NameSpace
> >>>> Dim myInbox As Outlook.MAPIFolder
> >>>> Dim myDestFolder As Outlook.MAPIFolder
> >>>> Dim myItems As Outlook.Items
> >>>> Dim myItem As Object
> >>>> Set myNameSpace = myOlApp.GetNamespace("MAPI")
> >>>> Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
> >>>> Set myItems = myInbox.Items
> >>>
>>>>> Set myDestFolder =
> >>>> Outlook.Session.Folders("PersonalFolder").Folders("PersonNameFolder")
> >>>> Set myItem = myItems.Find("[SenderName] = 'PersonName'")
> >>>> While TypeName(myItem) <> "Nothing"
> >>>> myItem.Move myDestFolder
> >>>> Set myItem = myItems.FindNext
> >>>> Wend
> >>>> End Sub
> >>> .
> >>>

> > .
> >
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
B Move Sent Email to archival pst folder and mark as read - HOW TO Outlook VBA and Custom Forms 2
S how automatically move messages after they've been read to a particular folder Using Outlook 1
D A way to create a rule to move messages to specific folder after read? Using Outlook 2
P Move emails between 2 mailboxes. Using Outlook 1
C Copy Move item won't work Outlook VBA and Custom Forms 2
N Macro to move all recipients to CC while replying Outlook VBA and Custom Forms 0
Commodore Move turns into "copy" Using Outlook 3
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
Jennifer Murphy Ctrl+Tab sometimes will not move through text a word at a time Using Outlook 1
V Outlook 2016 will not move emails in search results Using Outlook 4
M move to iCloud not working in outlook calendar Using Outlook 12
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
Commodore Folders always closed in move/copy items dialog box Using Outlook 3
C Move Outlook 2007 to new PC with Outlook 365 Using Outlook 3
C Can't move folder, the folder is full Using Outlook 0
Nadine Rule to move attachments with specific name Outlook VBA and Custom Forms 1
A Move email items based on a list of email addresses Outlook VBA and Custom Forms 40
T Move calendar invites to new calendar Using Outlook 5
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1
I Automating message move between folders Outlook VBA and Custom Forms 0
K Outlook Rules: Move a Copy Using Outlook 4
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
N Move emails of same conversation to same subfolder Using Outlook 6
P when i move inbox mails to another folder in outlook the mail disappears Using Outlook 1
Peter H Williams How to Move Mail item after processing Outlook VBA and Custom Forms 5
D Move Emails between Folders in Separate Mailbox Outlook VBA and Custom Forms 12
E Search for folder by key in subject then move new message to related folder Outlook VBA and Custom Forms 1
I Outlook 2013 Any way to move .OST file to new system? Using Outlook.com accounts in Outlook 5
O On click,I want to change subject line of selected mail and then reply to particular email and move Using Outlook 3
F "Move to" O365 feature to Outlook client via VBA Outlook VBA and Custom Forms 4
B Macro to manually move selected emails to network folder Outlook VBA and Custom Forms 1
L Making rule to move email to folder from one O365 domain Using Outlook 1
B Copy/Move Exchange inbox to Pop inbox Using Outlook 4
S Send email via SMTP - use transport rules to add to senders inbox (then rule to move to sent items Exchange Server Administration 1
C Move from Outlook 2007 Enterprise (MOE) to Outlook Pro plus 2007 Using Outlook 1
Cdub27 Move Outlook 2016 Contacts to Other Folders - Extremely Slow !! Using Outlook 6
M code to move selected Outlook contacts to another folder Using Outlook 3
Mark White VBScript Move sent mail to non-default folder Outlook VBA and Custom Forms 5
Mark White VBScript Move sent mail to non-default folder Outlook VBA and Custom Forms 0
G Favorites panel entries move around after restarting Outlook 2016 Using Outlook 1
M Move new mail to folder based on sender address Outlook VBA and Custom Forms 2
D Help with code to move mail on receipt to another folder based on time received Outlook VBA and Custom Forms 2
S VBA Code to move mail items from search folder to inbox subfolder Outlook VBA and Custom Forms 4
acpete48317 Categorize and move Outlook Email Outlook VBA and Custom Forms 2
Q VBA Script to move item in secondary mailbox Outlook VBA and Custom Forms 2
F Move mails from Deleted Items folder back to its original folder where the mails got deleted Using Outlook 0
L pin to Outlook move mail Using Outlook 2
S Auto move search results to folder Outlook VBA and Custom Forms 0
K VBA to move emails in folder to a windows folder Outlook VBA and Custom Forms 2
N Move red and unflagged emails to subfolder Outlook VBA and Custom Forms 1
Similar threads


















































Top