Pat_The_Bat
Board Regular
- Joined
- Jul 12, 2018
- Messages
- 83
Trying to write macro that will create an email object with a range of cells as the body. Ultimately I will probably set a cell as the "To" address, but for now I just wanted to get the mail object created with the contents from the page.
Any advice is greatly appreciated.
Code:
Sub CreateDocLlistMail()
Dim a As Integer
Dim objOutlook As Object
Dim objMail As Object
Dim rngTo As Range
Dim rngSubject As Range
Dim rngBody As Range
Dim rngAttach As Range
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
With Sheets("Publish Doc List")
'Set rngTo = .Cells(a, "C")
'Set rngSubject = .Cells(a, "E")
Set rngBody = .Range("B1:D28")
'Set rngAttach = .Range("B4")
End With
With objMail
'.To = rngTo.Value
'.Subject = rngSubject.Value
.Body = rngBody.Value
'.Attachments.Add rngAttach.Value
.Display 'Instead of .Display, you can use .Send to send the email _
or .Save to save a copy in the drafts folder
End With
Set objOutlook = Nothing
Set objMail = Nothing
Set rngTo = Nothing
Set rngSubject = Nothing
Set rngBody = Nothing
Set rngAttach = Nothing
End Sub
Any advice is greatly appreciated.