IntroductionOne of my projects, as a final step each month, emails the results to my client's clients.
Initial SolutionThe first working code I wrote for this is
Sub PrepareEmail(Optional Recipients As String, Optional CopiesTo As String, Optional Subj As String, _
Optional Msg As String, Optional AttachmentLocation As String, Optional HTMLMsgStyle As String)
Dim appOutlook As Outlook.Application
Dim EmailItem As Object
On Error GoTo PrepareMail_Error
Set appOutlook = New Outlook.Application
Set EmailItem = appOutlook.CreateItem(olMailItem)
.Display ' This must come before adding the Msg or the Signature will be wiped out
.To = Recipients
.CC = CopiesTo
.Subject = Subj
.HTMLBody = HTMLMsgStyle & "<p class=""msg"">" & Msg & "</p>" & EmailItem.HTMLBody
If IsAvailableFile(AttachmentLocation) Then
MsgBox "There was a problem generating emails. You will need to do this step manually."