Move Sent Email to archival pst folder and mark as read - HOW TO

Status
Not open for further replies.
B

BlueWolverine

Hello,

MS OUTLOOK 2003 on XP PRO

Awhile ago I was looking for how to do this and it was irritating me that it

was so hard to get a straight answer on how to pull this routine together.

So I thought I'd post sample code here to let everyone now how to do this

VERY simple thing.

Note: Occassionally, this thing de-initializes and won't trigger. If that

happens your email goes to your sent mail folder on the server side same as

always. No biggie, just close and re-open outlook to re-initialize or

manually run through the sub Application_Startup in the ThisOutlookSession

object. If I figure out how to prevent this from ever happening, I will

repost with better code.

I hope this is helpful to others. It really irked me that I couldn't find

seemingly simple sample code for this, so I thought I'd publish.

***I make no claims on the stability of this code, or it's reliability in

never causing problems. I believe it works well on my machine, and I think

it will work on yours but I have not rigorously tested it or done any

official software testing exercises. I am not responsible if this routine

eats your email by mistakes. It's not supposed to, but I don't KNOW that it

won't. Use at your own risk.

Macro to Mark as Read and Move to Archive Folder...

Copy and paste this to Objects 'This Outlook Session'

'**************************************

Dim classHandler As New cls_SentMail

Private Sub Application_StartUp()

classHandler.Initialize_handler

End Sub

'**************************************

Put in Class Module named 'cls_SentMail'

'*************************************

Dim myolApp As New Outlook.Application

Public WithEvents myOlItems As Outlook.Items

Public Sub Initialize_handler()

Set myOlItems =

myolApp.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items

End Sub

Public Sub myOlItems_ItemAdd(ByVal Item As Object)

Dim myNewFolder As Outlook.MAPIFolder

Dim myNameSpace As Outlook.NameSpace

Dim str_path As String

Dim str_pst As String

Dim str_folder As String

' User Defined Variables

str_path = "XXXXXXX.pst" 'This is the complete filepath for the PST

file you are using as an archive

str_pst = "Current" 'This is the name of the PST file as it

appears in the OUTLOOK window, below your inbox

str_folder = "Email" 'This is the name of the folder inside

str_pst that you want sent email move to.

Set myNameSpace = myolApp.GetNamespace("MAPI")

myNameSpace.AddStore (str_path)

Set myNewFolder = myNameSpace.Folders(str_pst).Folders(str_folder)

Item.Move myNewFolder

Item.UnRead = False

Item.Save

'Debug.Print Item.Subject

End Sub

BlueWolverine

MSE - Mech. Eng.

Go BLUE!
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
You had two questions and got two answers, which obviously helped you to

write this code. Why was that hard?

Best regards

Michael Bauer

Am Thu, 20 May 2010 12:57:01 -0700 schrieb BlueWolverine:


> Hello,
> MS OUTLOOK 2003 on XP PRO
> Awhile ago I was looking for how to do this and it was irritating me that


it
> was so hard to get a straight answer on how to pull this routine together.
> So I thought I'd post sample code here to let everyone now how to do this
> VERY simple thing.

> Note: Occassionally, this thing de-initializes and won't trigger. If that
> happens your email goes to your sent mail folder on the server side same


as
> always. No biggie, just close and re-open outlook to re-initialize or
> manually run through the sub Application_Startup in the ThisOutlookSession
> object. If I figure out how to prevent this from ever happening, I will
> repost with better code.

> I hope this is helpful to others. It really irked me that I couldn't find
> seemingly simple sample code for this, so I thought I'd publish.

> ***I make no claims on the stability of this code, or it's reliability in
> never causing problems. I believe it works well on my machine, and I


think
> it will work on yours but I have not rigorously tested it or done any
> official software testing exercises. I am not responsible if this routine
> eats your email by mistakes. It's not supposed to, but I don't KNOW that


it
> won't. Use at your own risk.

> Macro to Mark as Read and Move to Archive Folder...

> Copy and paste this to Objects 'This Outlook Session'
> '**************************************
> Dim classHandler As New cls_SentMail

> Private Sub Application_StartUp()
> classHandler.Initialize_handler
> End Sub
> '**************************************

> Put in Class Module named 'cls_SentMail'
> '*************************************
> Dim myolApp As New Outlook.Application
> Public WithEvents myOlItems As Outlook.Items

> Public Sub Initialize_handler()
> Set myOlItems =
> myolApp.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items
> End Sub

> Public Sub myOlItems_ItemAdd(ByVal Item As Object)

> Dim myNewFolder As Outlook.MAPIFolder
> Dim myNameSpace As Outlook.NameSpace

> Dim str_path As String
> Dim str_pst As String
> Dim str_folder As String

> ' User Defined Variables
> str_path = "XXXXXXX.pst" 'This is the complete filepath for the PST
> file you are using as an archive
> str_pst = "Current" 'This is the name of the PST file as


it
> appears in the OUTLOOK window, below your inbox
> str_folder = "Email" 'This is the name of the folder


inside
> str_pst that you want sent email move to.

> Set myNameSpace = myolApp.GetNamespace("MAPI")
> myNameSpace.AddStore (str_path)

> Set myNewFolder = myNameSpace.Folders(str_pst).Folders(str_folder)

> Item.Move myNewFolder
> Item.UnRead = False
> Item.Save

> 'Debug.Print Item.Subject

> End Sub
 
B

BlueWolverine

Re: Move Sent Email to archival pst folder and mark as read - HOW

Sorry. I think that was a bad day and I was in a rush. Looking back at all

the posts I got pretty good help.

I really appreciate all the hard work and help I've gotten from this forum.

I can't even begin to explain how much the Access and Excel sections bailed

me out, especially when I was learning Access.

Part of my irritation is that it felt like such a simple thing and I kept

thinking "There has to be sample code hanging around on the web for

this...There has to be something I can cherry pick." and then never finding

that. The other part is that I am used to the Access and Excel forums, where

I've typically gotten much more pseudocode based answers versus paragraphical

explanations.

Sorry. Re-reading my post, I sound really bitter.

I appreciate the help.

Thank you once again, and thank you to all the MVPs and Helpful friends on

the forum.

Have a wonderful day.

BlueWolverine

MSE - Mech. Eng.

Go BLUE!

"Michael Bauer " wrote:



> You had two questions and got two answers, which obviously helped you to
> write this code. Why was that hard?

> > Best regards
> Michael Bauer
> Category Manager -

> SAM - The Sending Account Manager:
>

> Am Thu, 20 May 2010 12:57:01 -0700 schrieb BlueWolverine:
>
> > Hello,
> > MS OUTLOOK 2003 on XP PRO
> > Awhile ago I was looking for how to do this and it was irritating me that

> it
> > was so hard to get a straight answer on how to pull this routine together.
> > So I thought I'd post sample code here to let everyone now how to do this
> > VERY simple thing.
> > Note: Occassionally, this thing de-initializes and won't trigger. If that
> > happens your email goes to your sent mail folder on the server side same

> as
> > always. No biggie, just close and re-open outlook to re-initialize or
> > manually run through the sub Application_Startup in the ThisOutlookSession
> > object. If I figure out how to prevent this from ever happening, I will
> > repost with better code.
> > I hope this is helpful to others. It really irked me that I couldn't find
> > seemingly simple sample code for this, so I thought I'd publish.
> > ***I make no claims on the stability of this code, or it's reliability in
> > never causing problems. I believe it works well on my machine, and I

> think
> > it will work on yours but I have not rigorously tested it or done any
> > official software testing exercises. I am not responsible if this routine
> > eats your email by mistakes. It's not supposed to, but I don't KNOW that

> it
> > won't. Use at your own risk.
> > Macro to Mark as Read and Move to Archive Folder...
> > Copy and paste this to Objects 'This Outlook Session'
> > '**************************************
> > Dim classHandler As New cls_SentMail
> > Private Sub Application_StartUp()
> > classHandler.Initialize_handler
> > End Sub
> > '**************************************
> > Put in Class Module named 'cls_SentMail'
> > '*************************************
> > Dim myolApp As New Outlook.Application
> > Public WithEvents myOlItems As Outlook.Items
> > Public Sub Initialize_handler()
> > Set myOlItems =
> > myolApp.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items
> > End Sub
> > Public Sub myOlItems_ItemAdd(ByVal Item As Object)
> > Dim myNewFolder As Outlook.MAPIFolder
> > Dim myNameSpace As Outlook.NameSpace
> > Dim str_path As String
> > Dim str_pst As String
> > Dim str_folder As String
> > ' User Defined Variables
> > str_path = "XXXXXXX.pst" 'This is the complete filepath for the PST
> > file you are using as an archive
> > str_pst = "Current" 'This is the name of the PST file as

> it
> > appears in the OUTLOOK window, below your inbox
> > str_folder = "Email" 'This is the name of the folder

> inside
> > str_pst that you want sent email move to.
> > Set myNameSpace = myolApp.GetNamespace("MAPI")
> > myNameSpace.AddStore (str_path)
> > Set myNewFolder = myNameSpace.Folders(str_pst).Folders(str_folder)
> > Item.Move myNewFolder
> > Item.UnRead = False
> > Item.Save
> > 'Debug.Print Item.Subject
> > End Sub

> .
>
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
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 Outlook 2013 - Email Gets Sent - But Does Not Move From Outbox to Sent Box Using Outlook 4
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1
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
M Move Sent Items from server folder to personal folder Using Outlook 2
S how to keep "To" when move sent emails to other folder Using Outlook 1
G Macro to move sent items from local folder to IMAP folder Using Outlook 4
R Move sent items emails to hard disk Using Outlook 10
N rule to move sent mail to the deleted folder in outlook Using Outlook 4
P move mails after send to central mailbox-sent items folder Using Outlook 4
O Outlook 2010: Rule to move sent emails doesn't start if I Use "Send To" command on a file on desktop Using Outlook 3
N Outlook - check sent items if messages sent from a specific account move it to another mailbox sent Using Outlook 3
J wireless always allows me to send/receive emails via outlook 2007. recent move to university gives me internet access but no emails can be sent or rec Using Outlook 1
B Create a rule to move emails after being sent to specific domains Outlook 2007 Using Outlook 1
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
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
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
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
Similar threads


















































Top