我有一组在 Outlook 2003、2007 和 2010 中有效的宏。事实上,除了特定情况外,它在 2013 年仍然有效。
每当您尝试发送电子邮件时,宏都会弹出一个对话框 - 用关键字标记主题行。问题是,如果我刚刚启动 Outlook,然后我打开了一封新电子邮件或回复 - Outlook 2013 中的默认设置是将其带入以前的“阅读窗格”而不是新窗口。如果我没有点击“弹出”并尝试发送,我的宏会因以下错误而崩溃:
“运行时错误 '91' 对象变量或未设置块变量”
我尝试先检查是否加载表单 - 但似乎对我的用户表单的任何调用,甚至是 userform.show,都会生成此错误。
奇怪的是,如果我记得“弹出”我的第一封电子邮件,它每次都运行良好,直到我关闭/重新打开 Outlook。即使我不“弹出”其他电子邮件。这只发生在第一个。
这是我的初始化事件的开始:
Dim Tags() As String
Dim T As Variant
Dim PC As Variant
Dim Rent As String
Dim Child As String
Dim nsourcefile As Integer
Dim email As MailItem
Dim PD As Variant
Dim Proj As String
Dim Desc As String
'Set email = Application.ActiveInspector.CurrentItem
Set email = Application.ActiveExplorer.Selection.Item(1)
'Checks to see if a project number (that's not on the list) may be in the subject already
If Val(email.Subject) > 10000 Then
TagMsg.Height = tall
TagMsg.NewProjID = Format(Val(email.Subject), "00000")
TagMsg.NewProjDesc.SetFocus
Else
'Set height of form (prior to pressing "More" button
TagMsg.Height = short
End If
注意到我将 Set email = Application.ActiveInspector.CurrentItem 更改为 Set email = Application.ActiveExplorer.Selection.Item(1)。这似乎已修复它,但 VBA 帮助声明“不要对 Item 方法返回类型做任何假设;您的代码应该能够处理多个项目类型或 ConversationHeader 对象。”
请注意,表单正在由 ItemSend 事件调用。