Application_Startup() 未触发

Rob*_*n A 1 outlook vba

我在“ThisOutlookSession”模块中编写了代码。

Application_ItemSend 有效,发送邮件时触发事件。

当我打开 Outlook 后手动启动 Application_Startup 时,Application_Startup 就会运行,而不是在启动时运行。

将子变量设置为私有没有什么区别 - 将变量设置为公共也没有什么区别。

我在信任中心的“启用所有宏”上有宏设置。

我在运行 Windows 10 企业版的电脑上使用 Outlook 2016。

我对这个问题进行了深入研究。

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
Run Code Online (Sandbox Code Playgroud)

小智 5

我测试了你的代码,我\xe2\x80\x99遇到了同样的问题。\n我通过重新启动我的电脑并添加 Public Sub Application_Quit() 方法解决了这个问题。

\n