Move all emails in one folder to another when exiting Outlook

L

linglc

All mails deleted from my Inbox will only be kept for one day in the "deleted
items" folder by my company. Hence, there are times when I lost some mails
because I forgot to move it out from there.
Can someone help me with this task? I want to move all emails in the
"deleted items" folder to another folder in the PST subfolder called "archive
items" whenever I close my Outlook? The PST folder is called "Operations
Finance". Thanks.
 
K

Ken Slovak - [MVP - Outlook]

The problem with that is by the time the Application.Quit event fires all
Outlook objects are out of scope. You would need to manually run the code
before trying to exit Outlook.

Depending on exactly where the "Operations Finance" folder is located the
code would look something like this, assuming that "Operations Finance" is a
subfolder of Deleted Items:

Sub SaveTheTrash()
Dim oSource As Outlook.MAPIFolder
Dim oTarget As OutlookMAPIFolder
Dim oDummy As Object
Dim oToMove As Object
Dim colItems As Outlook.Items
Dim i As Long

Set oSource = Application.Session.GetDefaultFolder(olFolderDeletedItems)
Set oTarget = oSource.Folders.Folder("Operations Finance")

Set colItems = oSource.Items

For i = colItems.Count To 1 Step -1
Set oToMove = colItems(i)
Set oDummy = oToMove.Move(oTarget)
Next
End Sub
 
L

linglc

Thanks! It is working now with minor tweaks.



Ken Slovak - said:
The problem with that is by the time the Application.Quit event fires all
Outlook objects are out of scope. You would need to manually run the code
before trying to exit Outlook.

Depending on exactly where the "Operations Finance" folder is located the
code would look something like this, assuming that "Operations Finance" is a
subfolder of Deleted Items:

Sub SaveTheTrash()
Dim oSource As Outlook.MAPIFolder
Dim oTarget As OutlookMAPIFolder
Dim oDummy As Object
Dim oToMove As Object
Dim colItems As Outlook.Items
Dim i As Long

Set oSource = Application.Session.GetDefaultFolder(olFolderDeletedItems)
Set oTarget = oSource.Folders.Folder("Operations Finance")

Set colItems = oSource.Items

For i = colItems.Count To 1 Step -1
Set oToMove = colItems(i)
Set oDummy = oToMove.Move(oTarget)
Next
End Sub
 
A

AndrewHa

Hi there,

I am looking at doing something similar but I have a personal folder called
"Personal Folders" with a "Deleted Items" Folder under this, what i would
ideally like to do is to move all the items in this Deleted Items folder to
the actual Deleted Items Folder in Outlook today.

You would be able to help me out with a solution to this please?

Thank you

Andrew

Could you please reply to the following email address please

(e-mail address removed)
 
K

Ken Slovak - [MVP - Outlook]

Please do not hijack threads. Start your own.

The view of Deleted Items in Outlook Today is just a view of the Deleted
Items folder. There's no difference between the two.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top