问题描述
我在ThisOutlookSession"模块中编写了代码.
I've code in the "ThisOutlookSession" module.
Application_ItemSend 有效,发送邮件时触发事件.
Application_ItemSend works, events are triggered when sending mail.
Application_Startup 在我打开 Outlook 后手动启动时运行 - 而不是在启动时.
Application_Startup runs when I initiate it manually after Outlook has been opened - not upon startup.
将 sub 设为私有没有任何区别 - 将变量设为公开也不行.
Making the sub private makes no difference - neither does making the variables public.
我在信任中心的启用所有宏"上有宏设置.
I have macro settings on "Enable all macros" in the Trust Center.
我在运行 Windows 10 企业版的 PC 上使用 Outlook 2016.
I'm on Outlook 2016 on a PC running Windows 10 Enterprise.
我已经深入研究了这个问题.
I have researched the issue intensively.
Option Explicit
Dim add_str As String
Public Sub Application_Startup()
Dim olNs As Outlook.NameSpace
Dim Folder As Outlook.MAPIFolder
Dim SubFolder As Outlook.MAPIFolder
Dim Item As Object
Set olNs = Application.GetNamespace("MAPI")
Set Folder = olNs.Folders("albrobin@workmail.com").Folders("WORKFLOW").Folders("Reporting")
For Each SubFolder In Folder.Folders
If SubFolder.items.Restrict("[UnRead] = True").Count > 0 Then
For Each Item In SubFolder.items
Item.UnRead = False
Next
End If
Next
End Sub
Public Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeName(Item) <> "MailItem" Then
Exit Sub
End If
If Item.Subject Like "RE: *" _
Or Item.Subject Like "AW: *" _
Or Item.Subject Like "FW: *" Then
Exit Sub
End If
UserForm1.Show
If add_str = "[URGENT] " Then
Item.Importance = olImportanceHigh
End If
Item.Subject = add_str & Item.Subject
add_str = vbNullString
End Sub
Public Sub routine(str_ As String)
add_str = Replace(str_, vbCrLf, " ")
add_str = "[" & add_str & "] "
End Sub
Sub show_form1()
UserForm1.Show
End Sub
推荐答案
我测试了您的代码,但遇到了同样的问题.我通过重新启动我的 PC 并添加 Public Sub Application_Quit() 方法解决了这个问题.
I tested your code and I’ve ran into the same problem.I have solved this problem by restarting my PC and adding the Public Sub Application_Quit() method.
这篇关于Application_Startup() 不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!