我正在尝试使我的Excel表能够在下一个截止日期到期时向我发送电子邮件提醒以与客户联系。
VBA给了我
VBA编译错误:未定义用户定义类型
Microsoft Outlook 16.0对象库被打勾。
Sub datesexcelvba()
Dim myApp As Outlook.Application
Dim mymail As Outlook.MailItem
Dim mydate1 As Date
Dim mydate2 As Long
Dim datetoday1 As Date
Dim datetoday2 As Long
Dim x As Long
lastrow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To lastrow
mydate1 = Cells(x, 12).Value
mydate2 = mydate1
Cells(x, 15).Value = mydate2
datetoday1 = Date
datetoday2 = datetoday1
Cells(x, 16).Value = datetoday
If mydate2 - datetoday2 = 0 Then
Set myApp = New Outlook.Application
Set mymail = myApp.CreateItem(olMailItem)
mymail.To = Cells(x, 11).Value
With mymail
.Subject = "Reminder"
.Body = Cells(x, 20).Text
.Display
'.send
End With
Cells(x, 13) = "Reminder sent"
Cells(x, 13).Interior.ColorIndex = 46
Cells(x, 13).Font.ColorIndex = 2
Cells(x, 13).Font.Bold = True
Cells(x, 14).Value = mydate2 - datetoday2
End If
Next
Set myApp = Nothing
Set mymail = Nothing
End Sub
预期结果是,它向我发送了一个提醒,其中包含(x, 20)
的正文内容,有关这些客户的mydate2 - datetoday = 0
。
答案 0 :(得分:0)
必须选中VBA->工具->参考-> Microsoft Office 16.0对象库的框
但是,当按计划的时间自动满足截止日期时,仍然没有向我发送提醒到我的邮箱中。其他错误代码。