vba - 预定的定期电子邮件
问题描述
下面的代码不会给出编译错误,但不会发送电子邮件。
目的是通过将它们链接到约会来发送定期电子邮件。
Private Sub Application_Reminder(ByVal Item As Object)
Dim xMailItem As MailItem
Dim xItemDoc As Word.Document
Dim xNewDoc As Word.Document
On Error Resume Next
If Item.Class <> OlObjectClass.olAppointment Then Exit Sub
If Item.Categories <> "Send Schedule Recurring Email" Then Exit Sub
Set xMailItem = Outlook.Application.CreateItem(olMailItem)
Set xItemDoc = Item.GetInspector.WordEditor
xItemDoc.Activate
xItemDoc.Application.Selection.WholeStory
xItemDoc.Application.Selection.Copy
With xMailItem
.To = Item.Location
.Subject = Item.Subject
Set xNewDoc = .GetInspector.WordEditor
xNewDoc.Activate
xNewDoc.Application.Selection.HomeKey
xNewDoc.Content.Paste
.Send
End With
Set xMailItem = Nothing
End Sub
似乎问题出在 Item.Class 中。我收到一条消息说
无效的外部程序。
解决方案
最后,我做了一点调情,发现了一些有用的提示,我最终解决了如下:
Dim WithEvents objReminders As Outlook.Reminders
Private Sub Application_Reminder(ByVal Item As Object)
Dim MItem As MailItem
Set MItem = Application.CreateItem(olMailItem)
If Item.MessageClass <> "IPM.Appointment" Then Exit Sub
If Item.Categories <> "Send Schedule Recurring Email" Then Exit Sub
MItem.To = Item.Location
MItem.CC = ""
MItem.BCC = ""
MItem.Subject = Item.Subject
MItem.BodyFormat = olFormatHTML
Item.GetInspector().WordEditor.Range.Copy
MItem.GetInspector().WordEditor.Range.Paste
MItem.Display
MItem.Send
Set MItem = Nothing
End Sub
Private Sub Application_Startup()
Set objReminders = Application.Reminders
End Sub
Private Sub objReminders_ReminderFire(ByVal ReminderOBject As Reminder)
If ReminderOBject.Item.Categories <> "Send Schedule Recurring Email" Then Exit Sub
ReminderOBject.Dismiss
End Sub
我希望它会有所帮助
推荐阅读
- mysql - django.db.utils.OperationalError: (2026, 'SSL connection error: SSL_CTX_set_tmp_dh failed') 同时连接到本地主机 MYSQL
- r - 'git2r_clone' 中的错误:尝试在 R 中克隆存储库时不受支持的 URL 协议
- apache-spark - 尝试访问 UDF 中的广播变量时,Spark 无限期冻结
- java - Dropwiazrd @CacheControl 未应用缓存控制标头
- vba - 如何使 VBA 宏窗体可扩展?
- android - 在 Flutter for BottomModalSheet 小部件中找不到脚手架错误,即使它是在脚手架内定义的
- excel - GetOpenFile 中的 InitialFileName 问题
- swift - 在 InsertItems(at:) 之后未调用 UICollectionView cellForItemAt - 如何预加载下一个单元格?
- algorithm - 如何用递归证明插入排序的正确性?
- android - 为什么在视图模型中声明变量时使用下划线 kotlin 约定