[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.8

Loop through folders and send to pst file

Asked by perkc in Outlook Groupware Software

Tags: loop, outlook, through

I'm having trouble with the following code.

I'm trying to loop through the parent folder of the default inbox and move all non default folders to an archive.

The correctly creates the archive and loops through until it hits a folder that should be moved but errors with #424(Object Required) on the indicated line.

Any thoughts?

Private Sub Command0_Click()
Dim oApplication As Outlook.Application
Dim oMapi As NameSpace
Dim oSentItemsFolder As MAPIFolder
Dim oDeletedItemsFolder As MAPIFolder
Dim oOtherFolder As MAPIFolder
Dim oOtherSubFolder As MAPIFolder
Dim oAAAArchive As MAPIFolder
Dim oSentArchive As MAPIFolder
Dim oDeleteArchive As MAPIFolder
Dim oInboxParentFolder As MAPIFolder
Dim oItems As Object
Dim ocurItem As MailItem
Dim oCheck As Double

DoCmd.SetWarnings False
DoCmd.Hourglass True

Set oApplication = New Outlook.Application
Set oMapi = oApplication.GetNamespace("MAPI")
Set oSentItemsFolder = oMapi.GetDefaultFolder(olFolderSentMail)
Set oDeletedItemsFolder = oMapi.GetDefaultFolder(olFolderDeletedItems)

For i = 1 To oMapi.Folders.Count
    If oMapi.Folders.Item(i).Name = "Personal Folders" Then
    oMapi.Folders.Item(i).Name = "Existing Personal Folders"
    End If
Next

oMapi.AddStore ("C:\AAA Archive.pst")
oMapi.Folders.Item("Personal Folders").Name = "AAA Archive"
Set oAAAArchive = oMapi.Folders.Item("AAA Archive")

'oMapi.AddStore ("C:\Sent Items Archive.pst")
'Set oSentArchive = oMapi.Folders.Item("Personal Folders")
'oSentArchive.Name = "Sent Items Archive"
'oSentItemsFolder.CopyTo oSentArchive

'oMapi.AddStore ("C:\Deleted Items Archive.pst")
'Set oDeleteArchive = oMapi.Folders.Item("Personal Folders")
'oDeleteArchive.Name = "Deleted Items Archive"
'oDeletedItemsFolder.CopyTo oDeleteArchive.Folders("Deleted Items")

Set oInboxParentFolder = oMapi.GetDefaultFolder(olFolderInbox).Parent

For Each oItems In oInboxParentFolder.Folders
   
    Select Case oItems.Name
       
        Case oMapi.GetDefaultFolder(olFolderCalendar).Name
        oCheck = 0
       
        Case oMapi.GetDefaultFolder(olFolderContacts).Name
        oCheck = 0
       
        Case oMapi.GetDefaultFolder(olFolderDeletedItems).Name
        oCheck = 0
       
        Case oMapi.GetDefaultFolder(olFolderDrafts).Name
        oCheck = 0
       
        Case oMapi.GetDefaultFolder(olFolderInbox).Name
        oCheck = 0
       
        Case oMapi.GetDefaultFolder(olFolderJournal).Name
        oCheck = 0
       
        Case oMapi.GetDefaultFolder(olFolderNotes).Name
        oCheck = 0
       
        Case oMapi.GetDefaultFolder(olFolderOutbox).Name
        oCheck = 0
       
        Case oMapi.GetDefaultFolder(olFolderSentMail).Name
        oCheck = 0
       
        Case oMapi.GetDefaultFolder(olFolderTasks).Name
        oCheck = 0
       
        Case "Synchronization Failures"
        oCheck = 0
       
        Case Else
        oCheck = 1
               
    End Select
   
    If oCheck = 1 Then
    Set oOtherFolder = oItems
    oOtherFolder.CopyTo (oAAAArchive) ' ERRORS OUT HERE BUT THE oOtherFolder variable has the correct name value
    Set oOtherFolder = Nothing
    End If
   
Next

'Do While oSentItemsFolder.Items.Count > 0
'    oSentItemsFolder.Items.Item(1).Delete
'Loop

'Do While oDeletedItemsFolder.Items.Count > 0
'    oDeletedItemsFolder.Items.Item(1).Delete
'Loop

For i = 1 To oMapi.Folders.Count
    If oMapi.Folders.Item(i).Name = "Existing Personal Folders" Then
    oMapi.Folders.Item(i).Name = "Personal Folders"
    End If
Next

Set oDeletedItemsFolder = Nothing
Set oSentItemsFolder = Nothing
Set oAAAArchive = Nothing
Set oSentArchive = Nothing
Set oDeleteArchive = Nothing
Set oOtherFolder = Nothing
Set oInboxParentFolder = Nothing
Set myitems = Nothing
Set oMapi = Nothing
oApplication.Quit
Set oApplication = Nothing

DoCmd.SetWarnings True
DoCmd.Hourglass False
MsgBox "Complete", vbOKOnly, "Outlook Archive Tool"
End Sub

Thanks,

perkc

[+][-]02/21/05 03:23 PM, ID: 13367557Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Outlook Groupware Software
Tags: loop, outlook, through
Sign Up Now!
Solution Provided By: BlueDevilFan
Participating Experts: 1
Solution Grade: A
 
[+][-]02/22/05 06:42 AM, ID: 13371795Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02/22/05 08:28 AM, ID: 13372936Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89