(This is a response to thread605-1547504)
Since this thread was already closed, and it took me several hours to accomplish my goal. I felt the need to share my work with others.
I do not claim any fame with this, I'm just borrowing from others work that I've managed to manipulate to my needs. There are probably an easier method, but I was unable to find it on Google.
There are two parts: 1) Function to translate the Outlook Folder path name; 2) A Sub that allows you to set which pst folders to move emails to.
In my case, I wanted to transfer all of my sent mails from the Exchanger Server account to a pst named "Sent Items 010108-", with a folder named Sent Items. Then copy all of the Drafts from the Server to my Personal Folders\Drafts folder. And finally, delete all of the Deleted Items on the Server.
Go to Outlook VBA, copy and paste (edit file locations as neccessary)
===================================================
'Sue Mosher
''DO NOT MODIFY THIS FUNCTION
Public Function GetFolder(strFolderPath As String) As MAPIFolder
' strFolderPath needs to be something like
' "Public Folders\All Public Folders\Company\Sales" or
' "Personal Folders\Inbox\My Folder"
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim colFolders As Outlook.Folders
Dim objFolder As Outlook.MAPIFolder
Dim arrFolders() As String
Dim I As Long
On Error Resume Next
strFolderPath = Replace(strFolderPath, "/", "\")
arrFolders() = Split(strFolderPath, "\")
Set objApp = Application
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.Folders.Item(arrFolders(0))
If Not objFolder Is Nothing Then
For I = 1 To UBound(arrFolders)
Set colFolders = objFolder.Folders
Set objFolder = Nothing
Set objFolder = colFolders.Item(arrFolders(I))
If objFolder Is Nothing Then
Exit For
End If
Next
End If
Set GetFolder = objFolder
Set colFolders = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Function
------------------------------
'Eric Legault
''EDIT FOLDER LOCATIONS HERE
'
Sub CleanOutlook()
On Error Resume Next
'Moves Sent Items
Set objDestinationFolder = GetFolder("Sent Items 010108-\Sent Items")
Set objSourceItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items
For Each objSourceItem In objSourceItems
objSourceItem.Move objDestinationFolder
Next
'Moves Drafts
Set objDestinationFolder = GetFolder("Personal Folders\Drafts")
Set objSourceItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts).Items
For Each objSourceItem In objSourceItems
objSourceItem.Move objDestinationFolder
Next
For Each objSourceItem In Application.GetNamespace("MAPI").GetDefaultFolder(olFolderDeletedItems).Items
objSourceItem.Delete
Next
End Sub
Since this thread was already closed, and it took me several hours to accomplish my goal. I felt the need to share my work with others.
I do not claim any fame with this, I'm just borrowing from others work that I've managed to manipulate to my needs. There are probably an easier method, but I was unable to find it on Google.
There are two parts: 1) Function to translate the Outlook Folder path name; 2) A Sub that allows you to set which pst folders to move emails to.
In my case, I wanted to transfer all of my sent mails from the Exchanger Server account to a pst named "Sent Items 010108-", with a folder named Sent Items. Then copy all of the Drafts from the Server to my Personal Folders\Drafts folder. And finally, delete all of the Deleted Items on the Server.
Go to Outlook VBA, copy and paste (edit file locations as neccessary)
===================================================
'Sue Mosher
''DO NOT MODIFY THIS FUNCTION
Public Function GetFolder(strFolderPath As String) As MAPIFolder
' strFolderPath needs to be something like
' "Public Folders\All Public Folders\Company\Sales" or
' "Personal Folders\Inbox\My Folder"
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim colFolders As Outlook.Folders
Dim objFolder As Outlook.MAPIFolder
Dim arrFolders() As String
Dim I As Long
On Error Resume Next
strFolderPath = Replace(strFolderPath, "/", "\")
arrFolders() = Split(strFolderPath, "\")
Set objApp = Application
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.Folders.Item(arrFolders(0))
If Not objFolder Is Nothing Then
For I = 1 To UBound(arrFolders)
Set colFolders = objFolder.Folders
Set objFolder = Nothing
Set objFolder = colFolders.Item(arrFolders(I))
If objFolder Is Nothing Then
Exit For
End If
Next
End If
Set GetFolder = objFolder
Set colFolders = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Function
------------------------------
'Eric Legault
''EDIT FOLDER LOCATIONS HERE
'
Sub CleanOutlook()
On Error Resume Next
'Moves Sent Items
Set objDestinationFolder = GetFolder("Sent Items 010108-\Sent Items")
Set objSourceItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items
For Each objSourceItem In objSourceItems
objSourceItem.Move objDestinationFolder
Next
'Moves Drafts
Set objDestinationFolder = GetFolder("Personal Folders\Drafts")
Set objSourceItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts).Items
For Each objSourceItem In objSourceItems
objSourceItem.Move objDestinationFolder
Next
For Each objSourceItem In Application.GetNamespace("MAPI").GetDefaultFolder(olFolderDeletedItems).Items
objSourceItem.Delete
Next
End Sub