ha ha not my rule mate but if a mod had seen it they would probably forbidden any replies until you did.
looks to be the bit
so maybe
Sub runMail()
Call OutlookMailSender
End Sub
Sub OutlookMailSender(Optional attachment)
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.recipient
Dim objOutlookAttach As Outlook.attachment
Dim bodytext As String
Dim recipient As String
Dim mBefore As Date
lastmonth = Format(DateAdd("m", -1, Now()), "yyyy-mmmm")'change format to your prefered layout
bodytext = "Hi " & vbNewLine & vbNewLine & vbNewLine & _
"This email was sent by Excel automation"
recipient = "[email protected]"
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(recipient)
objOutlookRecip.Type = olTo
Set objOutlookRecip = .Recipients.Add("[email protected]")
objOutlookRecip.Type = olCC
Set objOutlookRecip = .Recipients.Add("[email protected]")
objOutlookRecip.Type = olBCC
.Subject = "HELLO" & lastmonth 'or just lastmonth without the hello
.Body = bodytext
.Importance = olImportanceHigh
If Not IsMissing(attachment) Then
Set objOutlookAttach = .Attachments.Add(attachment)
End If
For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then MsgBox "Could not resolve the email for " & objOutlookRecip
Next
If True Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub
Bookmarks