Sub MailFindAndSend(strSubject As String)
Dim olApp As Outlook.Application
Dim nsNamespace As Outlook.NameSpace
Dim fldFolders As Outlook.Folders
Dim fldItFolder As Outlook.MAPIFolder
Dim miMail As Outlook.MailItem, miNewMail As Outlook.MailItem
Set olApp = CreateObject("Outlook.application")
Set nsNamespace = olApp.GetNamespace("MAPI")
Set fldFolders = nsNamespace.Folders
For Each fldItFolder In fldFolders
If FindInOlFolder(fldItFolder, strSubject, miMail) Then
Exit For
End If
Next
If Not IsNull(miMail) Then
Set miNewMail = olApp.CreateItem(olMailItem)
With miNewMail
.BodyFormat = olFormatPlain
.HTMLBody = "Some body text!"
.Subject = "Some subject!"
.Recipients.Add "[EMAIL="someone@email.com"]someone@email.com[/EMAIL]"
.Attachments.Add miMail
.Send
End With
Else
MsgBox "The mail could not be found."
End If
End Sub
Function FindInOlFolder(fldFolder As Outlook.MAPIFolder, strFindSubject As String, miResult As Outlook.MailItem) As Boolean
Dim miMail As Outlook.MailItem
Dim intIt As Integer
Dim fldNext As Outlook.MAPIFolder
For intIt = 1 To fldFolder.Items.Count
If fldFolder.Items(intIt) = strFindSubject Then
Debug.Print fldFolder.name
Set miResult = fldFolder.Items(intIt)
FindInOlFolder = True
Exit Function
End If
Next
For Each fldNext In fldFolder.Folders
If FindInOlFolder(fldNext, strFindSubject, miResult) Then
FindInOlFolder = True
Exit Function
End If
Next
FindInOlFolder = False
End Function