S
Steve Roberts
When I run the code below I receive the following error. ( I realize that
the code is very sloppy. I have copied pieces from several programming
examples and have not gone back to make everything uniform and give credits)
"The operation failed. An Object could not be found"
The Debug Stops at: olTempItem.Move myfolder.Folders(olNewFolder.Name).
The idea is that you select the folder you want to archive and the program
will create a .pst file for each subfolder and move items older than X to
the folder.
Thanks in advance for any suggestions you may have.
Steve
Sub ArchivePublicFolders()
Dim olNewFolder As Outlook.MAPIFolder
Dim olTempItem As Object
Dim myNS As Outlook.NameSpace
Dim myOlApp As New Outlook.Application
Dim CurrentFolder As Outlook.MAPIFolder
Dim olApp As Outlook.Application
Dim olSession As Outlook.NameSpace
Dim olStartFolder As Outlook.MAPIFolder
Set olApp = Application
Set olSession = olApp.GetNamespace("MAPI")
Set CurrentFolder = olSession.PickFolder
Set olNewFolder = CurrentFolder
Set olTempItem = CurrentFolder.Items
Set myOlApp = CreateObject("Outlook.Application")
Set MyNameSpace = myOlApp.GetNamespace("MAPI")
Set myfolder = MyNameSpace.GetDefaultFolder(olFolderInbox)
Set myRestrictItems = olTempItem.Restrict("[ReceivedTime] <
'11/30/2003'")
MyNameSpace.AddStore "c:\" & olNewFolder.Name & ".pst" 'Add or
Connect to .pst file
Set objFolder = MyNameSpace.Folders.GetLast 'Set objFolder to last
folder
objFolder.Name = olNewFolder.Name ' change the name that the user
sees in outlook
For Each olTempItem In myRestrictItems
olTempItem.Move myfolder.Folders(olNewFolder.Name)
Next
For Each olNewFolder In CurrentFolder.Folders
If olNewFolder.Name <> "Deleted Items" Then
ProcessFolder olNewFolder
MyNameSpace.AddStore "c:\" & olNewFolder.Name & ".pst"
End If
' MsgBox "sub folder change"
MsgBox olNewFolder.Name
Next
End Sub
the code is very sloppy. I have copied pieces from several programming
examples and have not gone back to make everything uniform and give credits)
"The operation failed. An Object could not be found"
The Debug Stops at: olTempItem.Move myfolder.Folders(olNewFolder.Name).
The idea is that you select the folder you want to archive and the program
will create a .pst file for each subfolder and move items older than X to
the folder.
Thanks in advance for any suggestions you may have.
Steve
Sub ArchivePublicFolders()
Dim olNewFolder As Outlook.MAPIFolder
Dim olTempItem As Object
Dim myNS As Outlook.NameSpace
Dim myOlApp As New Outlook.Application
Dim CurrentFolder As Outlook.MAPIFolder
Dim olApp As Outlook.Application
Dim olSession As Outlook.NameSpace
Dim olStartFolder As Outlook.MAPIFolder
Set olApp = Application
Set olSession = olApp.GetNamespace("MAPI")
Set CurrentFolder = olSession.PickFolder
Set olNewFolder = CurrentFolder
Set olTempItem = CurrentFolder.Items
Set myOlApp = CreateObject("Outlook.Application")
Set MyNameSpace = myOlApp.GetNamespace("MAPI")
Set myfolder = MyNameSpace.GetDefaultFolder(olFolderInbox)
Set myRestrictItems = olTempItem.Restrict("[ReceivedTime] <
'11/30/2003'")
MyNameSpace.AddStore "c:\" & olNewFolder.Name & ".pst" 'Add or
Connect to .pst file
Set objFolder = MyNameSpace.Folders.GetLast 'Set objFolder to last
folder
objFolder.Name = olNewFolder.Name ' change the name that the user
sees in outlook
For Each olTempItem In myRestrictItems
olTempItem.Move myfolder.Folders(olNewFolder.Name)
Next
For Each olNewFolder In CurrentFolder.Folders
If olNewFolder.Name <> "Deleted Items" Then
ProcessFolder olNewFolder
MyNameSpace.AddStore "c:\" & olNewFolder.Name & ".pst"
End If
' MsgBox "sub folder change"
MsgBox olNewFolder.Name
Next
End Sub