How do I send Email from outlook that contains cell value in the subject from an excel file?
I found every possible code to send email from excel but i really want to have the email open and in subject to have a cell value from an excel file.
And all this done from Outlook not from Excel. Thank you.
See Example below
Option Explicit
Sub Cell_Value_in_Subject()
Dim olItem As Outlook.MailItem
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSht As Excel.Worksheet
Dim sPath As String
sPath = "C:\Temp\Book1.xlsx" '<- Update
' // Excel
Set xlApp = CreateObject("Excel.Application")
' // Workbook
Set xlBook = xlApp.Workbooks.Open(sPath)
' // Sheet
Set xlSht = xlBook.Sheets("Sheet1")
Debug.Print xlSht.Range("A1") '<- Print Value in immediate window
' // Create e-mail Item
Set olItem = Application.CreateItem(olMailItem)
With olItem
.To = "Om3r@Email.com"
.Subject = xlSht.Range("A1")
.HTMLBody = xlSht.Range("A2") & " is Cell Value"
.Display
End With
' // Close
xlBook.Close SaveChanges:=True
' // Quit
xlApp.Quit
'// CleanUp
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSht = Nothing
Set olItem = Nothing
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.