Outlook VBA调试程序暂停,没有错误

时间:2016-01-04 17:58:14

标签: vba outlook

我有一个outlook宏绑定到键盘上的键,使用autohotkey。当我按y时,它会归档整个会话(ala Gmail)。它是通过在推送alt+3时发送y来实现的。这将运行"快速访问工具栏"中的第3项,这是以下脚本:

Sub ArchiveConversation()
    Set ArchiveFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders("Archive")
    If ArchiveFolder Is Nothing Then
          Set ArchiveFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders.Add("Archive")
    End If
    Set oStore = ArchiveFolder.Store
    Set selections = ActiveExplorer.Selection
    If selections.Count <> 0 Then
        For Each theSelection In selections
            Set oConv = theSelection.GetConversation
            If Not (oConv Is Nothing) Then
                 oConv.SetAlwaysMoveToFolder ArchiveFolder, oStore
                 oConv.StopAlwaysMoveToFolder oStore
            End If
        Next theSelection
    Else
        Set oConv = ActiveExplorer.Selection.GetSelection(Outlook.OlSelectionContents.olConversationHeaders).Item(1).GetConversation
        If Not (oConv Is Nothing) Then
             oConv.SetAlwaysMoveToFolder ArchiveFolder, oStore
             oConv.StopAlwaysMoveToFolder oStore
        End If
    End If
End Sub

脚本顺利运行。但是,在打开outlook后第一次运行脚本时,调试器会在启动Set ArchiveFolder的第一行打开并暂停。问题是,没有错误!我所要做的就是点击&#34;运行&#34;并且脚本完成正常。单步执行脚本会验证它没有问题,并且消息按预期存档。这真的很奇怪。任何人都知道这里发生了什么?

1 个答案:

答案 0 :(得分:0)

尝试停止,清除所有断点并重新启动Outlook。这件事发生在我身上,我在结束前留下了一个断点。