某些计算机上的Excel VBA中的Outlook“空白”字段

我们有一个Excel电子表格,用于为潜在客户创建报价.通过使用VBA,它可以生成PDF并使用Outlook将它们通过电子邮件发送给客户.它从主表单上的单元格中获取客户的电子邮件地址,用户填写客户的详细信息.

几周前,它已经停止在Outlook的“收件人”字段中填写客户的电子邮件地址,即使它已填写在主页上.

当我们更改此电子表格上的任何内容(包括代码)时,我们将其保存为新的“修订版”(保留所有以前的修订版.)回到之前的修订版,我现在发现它们都不起作用.这很奇怪,因为他们之前肯定做过.我正在使用Office 2016(虽然我刚刚升级,但这个问题是最近的.)运行Office 2013的计算机也无法运行.但是,运行Office 2007的计算机可以正常运行.

关于为什么现在这个问题的任何想法,以及为什么它只是某些版本的Office的问题?以下是代码片段:

    Private Sub send_as_pdf_Click()
    On Error GoTo ErrMsg
    Dim strPath As String, strFName As String
    Dim OutApp As Object, OutMail As Object

    strPath = Environ$("temp") & "\"

    strFName = Sheets("Quotation").Name & " " & Range("G18") & ".pdf"

    Sheets("Quotation").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        strPath & strFName, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

    strPath2 = Environ$("temp") & "\"

    strFName2 = Sheets("Quotation Offer Letter").Name & " " & Range("G18") & ".pdf"

    Sheets("Quotation Offer Letter").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        strPath2 & strFName2, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

    strPath3 = Environ$("temp") & "\"

    strFName3 = Sheets("Additional Works Required").Name & " " & Range("G18") & ".pdf"

    Sheets("Additional Works Required").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        strPath3 & strFName3, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "<p style='color:#2C3E50;font-family:Calibri;font-size:11pt;'>Hi " & Range("C9") & ",</p>"

    strbody2 = "<p style='color:#2C3E50;font-family:Calibri;font-size:11pt;'>The content of the email goes here.</p>"

    On Error Resume Next
    With OutMail
        .Display
        .To = Range("C19")
        .CC = ""
        .BCC = "first@person.com" & ";" & "second@person.com" & ";" & Range("I6") & ";"
        .Subject = "Quotation"
        .HTMLBody = strbody & strbody2 & .HTMLBody
        .Attachments.Add strPath & strFName
        .Attachments.Add strPath2 & strFName2
        .Attachments.Add strPath3 & strFName3
        .Attachments.Add ("C:\Terms and Conditions of Business of Our Business.pdf")
        .Attachments.Add ("C:\Warranty Statement of Our Business.pdf")
    End With

    Kill strPath & strFName
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
Exit Sub

ErrMsg:
MsgBox ("MUST enter Issue Number, Date & Customer Info."), , "Customer Email Error Message"

End Sub

最佳答案 试试这个:

注释这一行,这样你就可以看到错误是什么并进行调试.

'On Error Resume Next

完成后,您应该能够看到行内的错误:

.To = Range("C19")

《某些计算机上的Excel VBA中的Outlook“空白”字段》

在excel中,这将返回范围的值,但是您将该值发送到期望字符串的另一个应用程序Outlook.

我改变了这一行:

.To = Range("C19").Value2

它起作用了

点赞