电子邮件从外观与Excel单元格值在主题 [英] Email from outlook with Excel cell value in subject
本文介绍了电子邮件从外观与Excel单元格值在主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从excel文件发送包含主题中的单元格值的Outlook的电子邮件?
How do I send Email from outlook that contains cell value in the subject from an excel file?
我发现每个可能的代码都能从excel发送电子邮件,但我真的想让电子邮件打开,并且具有来自excel文件的单元格值。
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.
所有这些都是从Outlook而不是从Excel完成的。谢谢。
And all this done from Outlook not from Excel. Thank you.
推荐答案
请参阅下面的示例
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
这篇关于电子邮件从外观与Excel单元格值在主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文