Excel 2016 中的“对象 '_mailItem' 的方法 'To' 失败”错误

问题描述 投票:0回答:1

我在 excel 2016 中用宏编写了一个程序,通过创建一个按钮来向收件人发送邮件

B16 单元格包含我的收件人邮件 ID 当我运行此代码时,它显示了image1的错误 和 图像2错误 在这一行中它向我显示了这个错误 请帮我解决这个错误 而且现在 Outlook 已更改为 Outlook New(这也是出现此错误的原因之一) 当我运行代码时,它应该发送到邮件,但它显示了这个错误

请尽快帮忙

Sub EmailasPDF()
    Dim EApp As Object
    Set EApp = CreateObject("Outlook.Application")

    Dim EItem As Object
    Set EItem = EApp.CreateItem(0)

    Dim invno As Long
    Dim custname As String
    Dim amt As Currency
    Dim dt_issue As Date
    Dim pay_type As String
    Dim ref_no As String
    Dim term As Byte
    Dim path As String
    Dim fname As String
    Dim nextrec As Range

    invno = Range("C3")
    custname = Range("B11")
    amt = Range("H42")
    dt_issue = Range("C5")
    pay_type = Range("C6")
    term = Range("C7")
    ref_no = Range("C8")
    path = "C:\YEZLAW INVOICES DATA\PDF format\"
    fname = invno & " - " & custname


ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, IgnorePrintAreas:=False, Filename:=path & fname

    Set nextrec = Sheet3.Range("A1048576").End(xlUp).Offset(1, 0)

    nextrec = invno
    nextrec.Offset(0, 1) = custname
    nextrec.Offset(0, 2) = amt
    nextrec.Offset(0, 3) = dt_issue
    nextrec.Offset(0, 4) = dt_issue + term
    nextrec.Offset(0, 6) = pay_type
    nextrec.Offset(0, 9) = ref_no
    nextrec.Offset(0, 10) = Now

    Sheet3.Hyperlinks.Add anchor:=nextrec.Offset(0, 7), Address:=path & fname & ".pdf"

    With EItem

    .To = Range("B16")
    .Subject = "Invoice no: " & invno
    .Body = "Please find Invoice attached."
    .Attachments.Add (path & fname & ".pdf")
    .Display
    
    End With

End Sub

帮我解决这个错误以及宏代码

excel vba outlook
1个回答
0
投票

尝试换线

To = Range("B16")

To = Range("B16").Text
© www.soinside.com 2019 - 2024. All rights reserved.