简体   繁体   English

来自 Outlook 的电子邮件,主题为 Excel 单元格值

[英]Email from outlook with Excel cell value in subject

How do I send Email from outlook that contains cell value in the subject from an excel file?如何从 Excel 文件中的主题中包含单元格值的 Outlook 发送电子邮件?

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.我找到了所有可能的代码来从 excel 发送电子邮件,但我真的很想打开电子邮件,并且有一个来自 excel 文件的单元格值。

And all this done from Outlook not from Excel.而这一切都是通过 Outlook 而不是 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM