从Excel 2010通过Outlook发送电子邮件

时间:2018-03-07 16:56:41

标签: vba outlook excel-2010 outlook-vba

当我第一次开始在我之前创建一个由员工创建的新工作时,我提供了一个现有的VBA代码。不幸的是,当我第一次尝试运行它并且之前的员工无法访问时,它就不会运行。

我的目标是从现有的Excel电子表格中获取信息,并向电子表格上的人发送大量电子邮件。

我曾尝试多次编辑代码并将其带到当地大学的IT部门,但是一旦我到达我的工作计算机就无法运行。目前,错误代码为:

  

“编译错误:用户定义的类型未定义”

对此事项的任何帮助将不胜感激。我复制了以下代码:

Sub SendEmail(what_address As String, subject_line As String, mail_body As String)

    Dim olApp As Outlook.MailItem
    Set olApp = olApp.createitem(olMailItem)

    olMail.To = what_address
    olMail.CC = "someone@nogo.net"
    olMail.Subject = subject_line
    olMail.bodyformat = olFormatHTML
    olMail.htmlbody = mail_body
    olMail.attachments.Add ("C:\Users\129020\Desktop\90DayNotice\RecertWorkshopFlyerFY17")
    olMail.attachments.Add ("C:\Users\129020\Desktop\90DayNotice\RecertApplicationFY17.pdf")
    olMail.body = mail_body

    olMail.Send

End Sub

Sub SendMassEmail()

    row_number = 1

    Do
    DoEvents
        row_number = row_number + 1
        Dim mail_body_message As String
        Dim full_name As String
        Dim Company_Name As String

        mail_body_message = Sheet8.Range("I2")
        full_name = Sheet8.Range("B" & row_number)
        Company_Name = Sheet8.Range("C" & row_number)
        mail_body_message = Replace(mail_body_message, "replace_name_here", full_name)
        mail_body_message = Replace(mail_body_message, "replace_company_here", Company_Name)


         'MegBox (Sheet.Range("J3"))
          Call SendEmail(Sheet8.Range("D" & row_number), "RECERTIFICATION APPLICATION 90 DAY NOTICE", mail_body_message)
    Loop Until row_number = 18

MsgBox "Complete"

End Sub

0 个答案:

没有答案