我正在尝试编写一些需要具有特定数据的代码,同时仍然保留默认签名。
例如,如果我使用该功能.Body将使用正文文本替换电子邮件的全部内容。
Sub ListView41_DblClick()
Dim strName As String
Dim strEmail As String
Dim strEmail1 As String
Dim OutApp As Object
Dim OutMail As Object
Dim Singlepart As String
Dim SigString As String
Dim Signature As String
Dim strbody As String
Dim SigFilename
strName = ListView41.SelectedItem.Text
strEmail = ListView41.SelectedItem.ListSubItems(1).Text
strEmail1 = ListView41.SelectedItem.ListSubItems(2).Text
check = MsgBox("Send e-mail, To : " & strName & " - " & strEmail & "?" & vbNewLine & _
"CC : " & strEmail1, vbYesNo)
'UserForm1.Show
If check <> vbYes Then Exit Sub
Singlepart = MsgBox("For Single Part or Multiple Parts ? " & vbNewLine & vbNewLine & _
"Single Part = Yes" & vbNewLine & _
"Multiple Parts = No", vbYesNo)
If Singlepart = vbYes Then
' For Single Part Numbers
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _
"Please visit this website to download the new version.<br>" & _
"Let me know if you have problems.<br>" & _
"<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _
"<br><br><B>Thank you</B>"
'Signature of User
SigString = Environ("appdata") & _
"\Microsoft\Signatures\Rohith UTAS.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
On Error Resume Next
Userform1.Show
'With Outlook
With OutMail
.Display
.To = strEmail
.CC = strEmail1
.BCC = ""
.Subject = strName & "_Request for Product Information"
.HTMLBody = strbody & vbNewLine & Signature
.Display 'or .Display if you want the user to view e-mail and send it manually
End With
Else
' For Multiple Part Numbers
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'Signature of User
SigString = Environ("appdata") & _
"\Microsoft\Signatures\Rohith UTAS.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
On Error Resume Next
'With Outlook
With OutMail
.To = strEmail
.CC = strEmail1
.BCC = ""
.Subject = strName & "_Request for Product Information"
.HTMLBody = "<br>" & _
"Hi," & "<br>" & "<br>" & _
"Can you please provide me the Lifecycle and Years of Availability for the below listed parts?" & "<br />" & "<br />" & _
"The list of parts are : " & "<br />" & "<br />" & "<br />" & "<br />" & "<br />" & "<br />" & Signature
.Display 'or .Display if you want the user to view e-mail and send it manually
End With
End If
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
答案 0 :(得分:0)
在写入.body之前,检查其中已有的内容,看它是否预先填写了签名。如果是这样,请将您的代码更改为:
.body = newtext & .body
答案 1 :(得分:0)
每次创建新项目时都无需包含/添加签名模板。默认签名会自动添加,您只需要在邮件项目的开头添加内容,如 rgo 所示:
mailItem.HTMLBody = ModifyTheExistingBody(mailItem.HTMLBody);
ModifyTheExistingBody 函数在HTML标记中插入有效的HTML标记。
Outlook对象模型提供了三种使用项主体的方法:
您可以在MSDN中的Chapter 17: Working with Item Bodies中详细了解所有这些方法。