PDA

View Full Version : Mass move e-mails from different folders



Sidewinder31
07-26-2011, 11:35 AM
Hey guys, I'm having a problem getting this to work. My ultimate goal is to create an Outlook.MAPIFolder array and be able to loop through that array in order to move from a specific folder to a specific folder - or to delete from a specific folder.

The issue I am running up against is in the OpenMAPIFolder function. It's returning an Error 91 and I have no idea why. Please see below code:


Function OpenMAPIFolder(ByVal szPath As String) As Outlook.MAPIFolder
On Error GoTo ErrHandler
Dim app As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim flr As Outlook.MAPIFolder
Dim szDir As String
Dim i As Long

If Left(szPath, Len("\")) = "\" Then
szPath = Mid(szPath, Len("\") + 1)
Else
Set flr = app.ActiveExplorer.CurrentFolder
End If
While szPath <> ""
i = InStr(szPath, "\")
If i Then
szDir = Left(szPath, i - 1)
szPath = Mid(szPath, i + Len("\"))
Else
szDir = szPath
szPath = ""
End If
If flr Is Nothing Then
Set ns = app.GetNamespace("MAPI")
Set flr = ns.Folders(szDir)
Else
Set flr = flr.Folders(szDir) '<--Error occurs here and goes to ErrHandler.
End If
Wend
Set OpenMAPIFolder = flr
ErrHandler:
Debug.Print vbCr & Err.Number & " " & Err.Description '<-- Returns 91 Object variable or With block variable not set
End Function


Any help would be very appreciated! I'm hoping to be able to click a button to do this task instead of spending hours manually per time. Thanks!

-- Eric

JP2112
08-04-2011, 01:03 PM
Can you provide an example of how you are calling this function, thanks