Application_Startup()未触发

问题描述 投票:0回答:3

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

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

Application_Startup在我打开Outlook后手动启动时运行-不是在启动时运行。

将子项目设为私有没有区别-公开变量也没有。

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

我正在运行Windows 10 Enterprise的PC上使用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("[email protected]").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
vba outlook outlook-vba
3个回答
3
投票

我测试了您的代码,但遇到了同样的问题。我已经通过重新启动PC并添加Public Sub Application_Quit()方法解决了此问题。


0
投票

在重新加载和还原我的VBAProject之后,Application_Startup()过程也遇到同样的问题,因此无法触发。检查宏设置,对项目进行数字签名-祝您好运。在启动期间(如在Office 2010中)未收到用于启用VBA的按钮。VBA可以运行,但需要我手动触发Application_Startup()过程。

尝试创建一个新的临时“ Private Application_Startup()”过程,但没有乐趣。

我删除了Application_Startup()声明之前的“公共”语句。保存,关闭的VBA和Outlook。重新打开,突然开始工作。恢复了“公共”,保存,重新打开,现在看来可以正常工作。没有解释。


0
投票

有类似的问题。 Application_Startup没有在重新启动Outlook时触发,因此我对函数的更改没有加载。 Application_Startup未触发的原因是因为我有另一个程序持有对Outlook打开的引用

© www.soinside.com 2019 - 2024. All rights reserved.