FredrikUhre
New Member
- Joined
- Dec 13, 2024
- Messages
- 2
- Office Version
- Prefer Not To Say
- Platform
- Windows
Hello
I have created a code so the subject and body of the e-mail is based on a specific cell. Can anybody tell how to make the string for the recipient, based on a specifik cell.
My code is down below, i hobe somebody can help me with this problem.
I have created a code so the subject and body of the e-mail is based on a specific cell. Can anybody tell how to make the string for the recipient, based on a specifik cell.
My code is down below, i hobe somebody can help me with this problem.
VBA Code:
Sub SendEmail()
Dim objOutlook As Object
Dim objMail As Object
Dim strTo As String
Dim strSubject As String
Dim strBody As String
'Set email properties
strTo = Sheets("Ark1").Cells(4, 2)
strSubject = Sheets("Ark1").Cells(2, 2)
strBody = Sheets("Ark1").Cells(1, 2)
'Create Outlook object
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
'Set email recipients, subject, and body
With objMail
.To = strTo
.Subject = strSubject
.Body = strBody
.Send
End With
'Clean up
Set objMail = Nothing
Set objOutlook = Nothing
End Sub