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.
Similar threads
Thread starter Title Forum Replies Date
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
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
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
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

Similar threads

Top