I'm not sure if this is the right forum.
1. I'm trying to loop through all the pst files in my c:\ looking for specific date/time of email as well as to/from on the email.
2. Once I find these I would like to copy the emails to a new pst file.
I've found some code, but not sure if it's what I need since I'm new to outlook vba.
thx for any help
1. I'm trying to loop through all the pst files in my c:\ looking for specific date/time of email as well as to/from on the email.
2. Once I find these I would like to copy the emails to a new pst file.
I've found some code, but not sure if it's what I need since I'm new to outlook vba.
Code:
Public Sub LoopFolders(oFolders As MAPIFolder, ByVal bRecursive As Boolean)
Dim oFld As MAPI.Folder
For Each oFld In oFolders
LoopItems oFld
If bRecursive Then
LoopFolders oFld.Folders, bRecursive
End If
Next
End Sub
Private Sub LoopItems(oFld As MAPIFolder)
Dim obj As Object
Dim oItems As MAPI.Messages
Set oItems = oFld.Messages
For Each obj In oItems
Select Case True
Case (TypeOf obj Is MAPI.Message)
HandleMessage obj
Case (TypeOf obj Is MAPI.AppointmentItem)
' ...
End Select
Next
End Sub
Private Sub HandleMessage(oItem As MailItem)
' ...
End Sub
Private Sub btnCloseAll_Click()
Dim objol As NameSpace
Set objName = objol.GetNamespace("MAPI")
Set Shells = CreateObject("Shell.Application")
Set Folder = Shells.NameSpace("C:\Outlookfiles")
Set Items = Folder.Items
For i = 0 To Items.Count - 1
Set Item = Items.Item(i)
ItemName = Item.Name
If Not Item.IsFolder Then
FileName = Item.Path
If UCase(Right(FileName, 4)) = ".PST" Then
lenItemName = Len(ItemName)
TrimmedLength = lenItemName - 4
FinalName = Left(ItemName, TrimmedLength)
Set objFolder = objName.Folders.Item(FinalName)
objName.RemoveStore objFolder
End If
End If