出于某种原因,这只是将路径设置为指定的NCR编号(即R:\ Quality \ NCR的[此处为NCR编号],就是这样)。我无法弄清楚为什么它不会将其余信息(PN和.xlsm)拉入链接。请帮忙!
Dim Email_Subject, Email_Send_From, Email_Send_To, _
Email_Cc, Email_Bcc, Email_Body As String
Dim Mail_Object, Mail_Single As Variant
Dim PN As String
Dim NCR As String
Dim my_hyperlink As String
PN = Worksheets("Sheet1").Range("C12").Value
NCR = Worksheets("Sheet1").Range("I4").Value
my_hyperlink = "R:\Quality\NCR's\" & NCR & " " & PN & ".xlsm"
On Error GoTo debugs
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
.Subject = "NCR: Part Failed Appearance"
.To = "me@workemail.com"
.cc = "me@workemail.com"
.HTMLBody = PN & " has failed for appearance issues and requires a marketing disposition. This part has been cleared by engineering. Please see NCR number " & NCR & " in NCR Log for more details. See the Report <a href=" & my_hyperlink & ">Here</a>"
.send
End With
答案 0 :(得分:0)
字符串连接运算符&amp; (或+)每边需要一个操作数。
Email_Body = PN & " has failed for ap
应该是
rs.MoveLast
答案 1 :(得分:0)
正如其他人所说,行:
Email_Body = & PN & " has failed for appearance issues and requires a marketing disposition. This part has been cleared by engineering. Please see NCR number " & NCR & "in NCR Log for more details."
应改为:
Email_Body = PN & " has failed for appearance issues and requires a marketing disposition. This part has been cleared by engineering. Please see NCR number " & NCR & "in NCR Log for more details."
因为你在开始时不需要&符号。
就超链接而言,您可以执行以下操作:
dim my_hyperlink as string
my_hyperlink = "R:\Quality\" & NCR & "'s\" & NCR & " " & PN & ".xlsm"
要将此添加到电子邮件中,您应该使用.HTMLBody
,然后将这些行替换为这些(我在句子末尾添加了超链接):
Email_Body = PN & " has failed for appearance issues and requires a marketing disposition. This part has been cleared by engineering. Please see NCR number " & NCR & "in NCR Log for more details. The hyperlink is <a href=" & my_hyperlink & ">click here</a>"
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.cc = Email_Cc
.BCC = Email_Bcc
.HTMLBody = Email_Body
.send
End With
为了提高效率和可读性,您可以将代码更改为:
Sub emailmarketing()
Dim Email_Subject, Email_Send_From, Email_Send_To, _
Email_Cc, Email_Bcc, Email_Body As String
Dim Mail_Object, Mail_Single As Variant
Dim PN As String
Dim NCR As String
PN = Worksheets("Sheet1").Range("C12").Value
NCR = Worksheets("Sheet1").Range("I4").Value
On Error GoTo debugs
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
.Subject = "Non-Conformance Report: Part Failed Appearance"
.To = "me@workemail.com"
.cc = "me@workemail.com"
.HTMLBody = PN & " has failed for appearance issues and requires a marketing disposition. This part has been cleared by engineering. Please see NCR number " & NCR & "in NCR Log for more details. The hyperlink is <a href=" & my_hyperlink & ">click here</a>"
.send
End With
debugs:
If Err.Description <> "" Then MsgBox Err.Description
End Sub
让我知道这是否有效:)