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

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

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

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

> .
>
 
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.
Similar threads
Thread starter Title Forum Replies Date
B Move Sent Email to archival pst folder and mark as read - HOW TO Outlook VBA and Custom Forms 2
H Move Selected emails to Local Drive Outlook VBA and Custom Forms 0
A Search folder and move the email Outlook VBA and Custom Forms 0
A Outlook 365 (OutLook For Mac)Move "On My Computer" Folder Items From Old To New Mac Computer Using Outlook 3
HarvMan Outlook 365 - Rule to Move an Incoming Message to Another Folder Using Outlook 4
humility36 Cannot move emails to archive - 440 error Outlook VBA and Custom Forms 1
B Outlook 2019 Automatically move email after assigning category Using Outlook 4
C Trying to move messages between imap accounts/folders Using Outlook 5
M Move command Outlook VBA and Custom Forms 11
C Code to move mail with certain attachment name? Does Not work Outlook VBA and Custom Forms 3
B Move emails from one account to another Outlook VBA and Custom Forms 2
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
N How to add or delete items to Move dropdown Menu Using Outlook 0
Commodore Unable to move message Using Outlook 3
N Line to move origEmail to subfolder within a reply macro Outlook VBA and Custom Forms 0
C Move or copy from field to field Outlook VBA and Custom Forms 0
T Outlook 365 Move newly created tasks automatically on save. Outlook VBA and Custom Forms 1
NVDon Create new Move To Folder list Outlook VBA and Custom Forms 0
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
T Macro to move reply and original message to folder Outlook VBA and Custom Forms 6
F VBA to move email from Non Default folder to Sub folders as per details given in excel file Outlook VBA and Custom Forms 11
F Excel VBA to move mails for outlook 365 on secondary mail account Outlook VBA and Custom Forms 1
J Dopey move - deleted profile Using Outlook 1
GregS Outlook 2016 Move Outlook to new computer? Using Outlook 4
Witzker Macro to move @domain.xx of a Spammail to Blacklist in Outlook 2019 Outlook VBA and Custom Forms 7
G Move tasks up/down todo list by VBA Outlook VBA and Custom Forms 1
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
D Move Email with Attachment to Folder Outlook VBA and Custom Forms 3
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
G Cannot Move Autocomplete File to New Computer Using Outlook 15
M Move to Folder Using Outlook 1
P Move emails between 2 mailboxes. Using Outlook 0
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

Similar threads

Back
Top