【发布时间】:2021-02-09 07:01:30
【问题描述】:
我正在使用 Excel。我想以特定格式起草一封电子邮件。
我在这种格式的电子邮件中找不到任何内容:
- 单词
- 图片
- 单词
- 图片
- 单词
- 签名
我找到了我用来构建我的文字、图像、图像和签名的那些。
我将所有我尝试过的内容都保留为注释掉的部分。
Sub EmailGenerate()
Dim objOutApp As Object, objOutMail As Object
Dim strBody As String, strSig As String, strEnd As String, strBody2 As String
Dim rng As Range, rng2 As Range
Dim r As Long, r2 As Long
Dim wdDoc As Word.Document
Dim Selection As Word.Selection
Dim Selection2 As Word.Selection
r = shEmail.Cells(Rows.Count, 15).End(xlUp).Row
Set rng = shEmail.Range("K1:" & Cells(r, 21).Address)
r2 = shEmail.Cells(Rows.Count, 23).End(xlUp).Row
Set rng2 = shEmail.Range("W1:" & Cells(r2, 29).Address)
Set objOutApp = CreateObject("Outlook.Application")
Set objOutMail = objOutApp.CreateItem(0)
Set wdDoc = objOutMail.GetInspector.WordEditor
With objOutMail
'If sent on behalf of another email address
' .SentOnBehalfOfName = ""
'Setting the email conditions
.To = shEmail.Cells(1, 2).Value
.CC = shEmail.Cells(2, 2).Value
.BCC = ""
'Checks all email names
.Recipients.ResolveAll
.Subject = shEmail.Cells(4, 2).Value
'This must be visible to get the default signature
.Display
'Get the html code from the signature
strSig = .htmlbody
'This is what the email body should say
' rng.Copy
' wdDoc.Application.Selection.Start = Len(strBody)
' wdDoc.Application.Selection.End = wdDoc.Application.Selection.Start
' wdDoc.Application.Selection.PasteAndFormat (wdChartPicture)
' wdDoc.Content.InsertParagraphAfter
' rng2.Copy
' wdDoc.Application.Selection.Start = Len(strBody) + Len(strBody2)
' wdDoc.Application.Selection.End = wdDoc.Application.Selection.Start
' wdDoc.Application.Selection.PasteAndFormat (wdChartPicture)
' rng1.Copy
' wdDoc.Paragraphs(2).Range.PasteSpecial , , , , wdPasteBitmap
rng.Copy
wdDoc.Content.InsertParagraphBefore
wdDoc.Paragraphs(2).Range.PasteSpecial , , , , wdPasteBitmap
wdDoc.Content.InsertParagraphAfter
strBody = "<Body style=font-size:11pt;font-family:Calibri>" & _
shEmail.Cells(5, 2).Value & "</p>" & _
"<p>" & "</p>" & _
"<p>" & shEmail.Cells(6, 2).Value & "</p>" & _
"<p>" & shEmail.Cells(7, 2).Value & "</p>" & _
"<p>" & "</p>" & _
"<p>" & shEmail.Cells(8, 2).Value & "</p>"
strBody2 = "<Body style=font-size:11pt;font-family:Calibri>" & _
shEmail.Cells(10, 2).Value & "</p>" & _
"<p>" & "</p>"
rng2.Copy
wdDoc.Content.InsertParagraphBefore
wdDoc.Paragraphs(1).Range.PasteSpecial , , , , wdPasteBitmap
wdDoc.Content.InsertParagraphAfter
objOutMail.htmlbody = strBody2 & _
.htmlbody
' rng2.Copy
' wdDoc.Application.Selection.Start = Len(strBody) + Len(strBody2)
' wdDoc.Application.Selection.End = wdDoc.Application.Selection.Start
' wdDoc.Application.Selection.PasteAndFormat (wdChartPicture)
'Combines the email with image and the signature
objOutMail.htmlbody = strBody & _
.htmlbody
'Automatically sends the email, should pop up briefly.
'.Send
End With
On Error GoTo 0
Set objOutMail = Nothing
Set objOutApp = Nothing
End Sub
rng 是较大的表,rng2 是较小的表。
.Cells(5,2) 到 (8,2) 位于 rng 之前,(10,2) 位于 rng 之后和 rng2 之前,那么 (12,2) 将位于 rng2 之后和签名之前。
【问题讨论】:
-
Steven hi - 信息很清楚,但我不确定确切的问题是什么:你能帮我一下吗?谢谢
-
您好约翰,感谢您的回复。很抱歉我的问题不是很清楚。我想在我的代码错误的地方得到帮助。或指导以更好的方式将其转换为我需要的格式。我在代码下方添加了一个简短的解释,以显示与代码保持一致的位置。我希望这是有道理的。谢谢
-
一个快速观察 - 你可能知道,但如果不是
"<p>" & "</p>"不会给你换行,你可以试试</br> -
我不知道,谢谢。
-
months和completed- 您正在寻找超链接?如果是这样,您将如何为此构建 html?