【问题标题】:Outlook VBA Runtime Error 91 Object variable or With block variable not setOutlook VBA 运行时错误 91 对象变量或未设置块变量
【发布时间】:2017-12-05 04:03:01
【问题描述】:

当用于“干净”的新电子邮件时,此宏可以正常工作。但是,当我回复或转发电子邮件时,我会收到 VBA

错误 91 - 对象变量或未设置块变量

Private WithEvents olRemind As Outlook.Reminders

Private Sub Application_Reminder(ByVal Item As Object)
Set olRemind = Outlook.Reminders

If Item.MessageClass <> "IPM.Task" Then
  Exit Sub
End If

If Item.Categories <> "Online" Then
  Exit Sub
End If

SetOnline

Timed_box (1)

Pause 30

SetOffline

Item.MarkComplete

Set olRemind = Outlook.Reminders
    For Each objRem In olRemind
            If Item.Categories = "Online" Then
                If objRem.IsVisible Then
                    objRem.Dismiss
                    Cancel = True
                End If
                Exit For
            End If
        Next objRem

End Sub

'Categorize Sent Items
'Place in ThisOutlookSession
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If TypeOf Item Is Outlook.MailItem And Len(Item.Categories) = 0 Then
        Set Item = Application.ActiveInspector.CurrentItem
        Item.ShowCategoriesDialog
    End If
End Sub

Set Item = Application.ActiveInspector.CurrentItem 是我需要调试的行。谢谢

【问题讨论】:

    标签: vba outlook


    【解决方案1】:

    我猜回复或转发位于 Outlook 底部的窗格中,即ActiveInlineResponse 窗格。我最近修改了一些代码以考虑该窗格。如果是这样的话,这样的事情可能对你有用:

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
        If TypeOf Item Is Outlook.MailItem And Len(Item.Categories) = 0 Then
        If Not Application.ActiveExplorer.ActiveInlineResponse Is Nothing Then
            Set Item = Application.ActiveExplorer.ActiveInlineResponse
        End If
        'If the draft is in it's own window
        If OutItem Mail Is Nothing Then
            If Not Application.ActiveInspector Is Nothing Then
            Set Item = Application.ActiveInspector.CurrentItem
            Item.ShowCategoriesDialog
        End If
    End Sub
    

    此代码未经测试,我可能没有正确粘贴/修改所有内容。

    【讨论】:

      【解决方案2】:

      Item 是传给 ItemSend 的,不用自己找。

      'Categorize Sent Items
      'Place in ThisOutlookSession
      Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
          If TypeOf Item Is Outlook.MailItem And Len(Item.Categories) = 0 Then
              Item.ShowCategoriesDialog
          End If
      End Sub
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-07
        • 2017-05-20
        相关资源
        最近更新 更多