好的,现在我上一篇文章中的变量传递已经解决了,新的问题又出现了。
单击“新电子邮件”按钮会触发例程,该例程显示用户表单,然后立即显示实际的邮件消息。但是,新消息会显示在用户窗体的顶部。可行,但不理想。
Private Sub objInsp_NewInspector(ByVal Inspector As Inspector)
Dim frm As frmNewEmail
Dim msg As Outlook.MailItem
If TypeName(Inspector.CurrentItem) = "MailItem" Then
If Inspector.CurrentItem.Subject <> "" Then
Exit Sub 'This procedure is only for new email mesages
End If
Set frm = New frmNewEmail
With frm
Set .Message = Inspector.CurrentItem
.StartUpPosition = 2
.Show False
End With
End If
End Sub
一个简单的解决方案是使用户表单模态化(删除 .Show 之后的 False 选项)。事实上,现在只显示用户表单,并且我假设电子邮件消息窗口正在等待用户表单被卸载。至少,这是我所期望的。
在用户窗体中单击一种语言后,用户窗体将被隐藏、卸载,并执行 MyNewEmail 过程,从而启动其他几个过程。
但是,我的代码现在在 Set objInsp = objItem.GetInspector 处执行这些过程时会抛出错误,而使用非模态用户窗体时,代码执行时不会出现错误。我在一些论坛上读到,要在显示的邮件项目上调用 GetInspector。但是,任何显示邮件消息的尝试也会导致错误。
有问题的代码是这样的:(objItem是
If msg.Class = olMail Then
Set objInsp = msg.GetInspector '<<< Throws an error if userform = Modal
If objInsp.EditorType = olEditorWord Then
If objInsp.CurrentItem.BodyFormat <> olFormatHTML Then
objInsp.CurrentItem.BodyFormat = olFormatHTML
End If
End If
Else
Exit Function
End If
我可以想到几个选项,但我使用的代码都没有解决此错误。
a)使新消息的检查器窗口可见(希望这有帮助)。但是,我无法识别 或 窗口。
b) 以非模式模式执行用户表单并最小化新电子邮件窗口。我尝试了 Application.ActiveWindow.WindowState = olMinimized,但在这种情况下,主 Outlook 窗口已最小化(消息窗口尚未显示)。
c)……?
有人遇到过这个问题吗?
我找到了解决方案!
Private WithEvents objOpenInsp As Outlook.Inspector
Private WithEvents objInsp As Outlook.Inspectors
Private Sub objInsp_NewInspector(ByVal Inspector As Outlook.Inspector)
If TypeName(Inspector.CurrentItem) = "MailItem" Then
Set objOpenInsp = Inspector
End If
End Sub
Private Sub objOpenInsp_Activate()
Dim objItem As Outlook.MailItem
Dim frm As frmLanguage
Dim lngLang As Long
Set objItem = objOpenInsp.CurrentItem
If Len(objItem.EntryID) = 0 And Len(objItem.Subject) = 0 Then
'This procedure is only for new email messages.
'Note that if you leave the subject line empty and try to close
'the objItem window, the Activate event is triggered too and may
'get stuck in a loop.
Set frm = New frmLanguage
frm.Show
lngLang = frm.lngRetValue
Unload frm
If lngLang > 0 Then
'MyNewMessage Inspector.CurrentItem, lngLang
MyNewMessage objItem, lngLang
Else 'User pressed Cancel or closed the form
objItem.Subject = " " 'prevent loop
objItem.Close olDiscard
End If
End If
Set frm = Nothing
Set objItem = Nothing
End Sub
再次感谢您的帮助!