Ive got the following code alongside two functions
The error im now getting is 'Object variable or With block variable not set'
Any clues ?
Code:
Sub MoveAllMessages_Click()
Dim olApp As Object
Dim Mapi As NameSpace
Dim olkSource As Outlook.MAPIfolder
Dim olkDestination As Outlook.MAPIfolder
Dim olkMsg As Outlook.MailItem
Dim intIndex As Integer
Dim Mail As MailItem
Set olkSource = OpenOutlookFolder(olFolderInbox)
Set olkDestination = OpenOutlookFolder("<My account name>").Folders("Test")
For intIndex = olkSource.Items.Count To 1 Step -1
olkSource.Items.Item(intIndex).Move olkDestination
Next
Mail.Move olkDestination
Set olkSource = Nothing
Set olkDestination = Nothing
Set olkMsg = Nothing
MsgBox "Finished!", vbInformation + vbOKOnly, "Move All Messages"
End Sub
Code:
Function IsNothing(obj)
If TypeName(obj) = "Nothing" Then
IsNothing = True
Else
IsNothing = False
End If
End Function
Code:
Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIfolder
Dim arrFolders As Variant, _
varFolder As Variant, _
olkFolder As Outlook.MAPIfolder
On Error GoTo ehOpenOutlookFolder
If strFolderPath = "" Then
Set OpenOutlookFolder = Nothing
Else
If Left(strFolderPath, 1) = "\" Then
strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
End If
arrFolders = Split(strFolderPath, "\")
For Each varFolder In arrFolders
If IsNothing(olkFolder) Then
Set olkFolder = Session.Folders(varFolder)
Else
Set olkFolder = olkFolder.Folders(varFolder)
End If
Next
Set OpenOutlookFolder = olkFolder
End If
On Error GoTo 0
Exit Function
ehOpenOutlookFolder:
Set OpenOutlookFolder = Nothing
On Error GoTo 0
End Function
Thanks for looking into this guys, really appreciate it !