Hi people.
Guys, i need help with adding a date to the subject line in outlook. basically when I click a button in excel I would like a populated email come up. But what I need to do is have the subject heading date change so it has the previous months date. ie November 2012. Could someone please show me how to do this?
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
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"
.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