我想发送一封带有Excel表格的电子邮件。
我想从多个单元格插入文本字符串到电子邮件标题。
我有代码从别人的形式,我试图修改。
标题不起作用,但据我所知其余的都起作用了。
Sub SendEmailFleet()
'
' SendEmailFleet Macro
'
Dim olapp As Outlook.Application
Dim olemail As Outlook.MailItem
Dim olinsp As Outlook.Inspector
Dim wddoc As Word.Document
Set olapp = New Outlook.Application
Set olemail = olapp.CreateItem(olMailItem)
With olemail
.BodyFormat = olFormatRichText
.Display
.To = "example@example.com"
.Subject = "Salgsmail" & " " & .Range("C25:D25") & " " & .Range("C23:D23")
Set olinsp = .GetInspector
Set wddoc = olinsp.WordEditor
wddoc.Range.InsertBefore " "
Sheet1.Activate
Range("A1").CurrentRegion.Copy
wddoc.Range(3, 3).Paste
End With
End Sub
你需要加入范围
的文本WorksheetFunction.TextJoin(" ", True, Sheet1.Range("C25:D25"))
那么你的.subject
应该是这样的:
.Subject = "Salgsmail" & " " & WorksheetFunction.TextJoin(" ", True, Sheet1.Range("C25:D25")) & " " & WorksheetFunction.TextJoin(" ", True, Sheet1.Range("C23:D23"))
所以我找到了解决方案,使用上面的混合:
.subject = "Salgsmail" & " " & Sheets("Sheet1").Range("C25").Value & " " & Sheets("Sheet1").Range("C23").Value
谢谢你的帮助!