【问题标题】:run a macro when creating new appointment in outlook在 Outlook 中创建新约会时运行宏
【发布时间】:2020-06-23 15:11:29
【问题描述】:

我是 Outlook vba 的新手。

我想在 Outlook 2016 32 位的 mycalendar 中创建新约会时运行宏

我试过了

Private WithEvents appt As Outlook.AppointmentItem

Private Sub appt_Write(Cancel As Boolean)
MsgBox ("test ok")
End Sub

在 ThisOutlookSession 模块中,但当我编辑并保存新约会时没有任何反应。

我必须做什么?

【问题讨论】:

    标签: vba outlook


    【解决方案1】:

    您的apt 变量永远不会被初始化并保持为空。尝试使用Application.Inspectors.MewInspector 事件来检查新约会何时打开,并在检查它确实是约会后设置为Inspector.CurrentItem。请注意,您可以打开多个约会,因此单个 apt 变量将不起作用,您需要有一个列表或数组。

    【讨论】:

      【解决方案2】:

      来自outlook event newMail (newItem)

      Private WithEvents appt As AppointmentItem
      Private WithEvents objinspectors As Outlook.Inspectors
      
      Private Sub Application_Startup()
          Set objinspectors = Application.Inspectors
      End Sub
      
      Private Sub objinspectors_NewInspector(ByVal Inspector As Inspector)
          If TypeName(Inspector.currentItem) = "AppointmentItem" Then
              MsgBox "newinspector"
              Set appt = Inspector.currentItem    ' <----
          End If
      End Sub
      
      Private Sub appt_Write(Cancel As Boolean)
          MsgBox ("test ok")
      End Sub
      

      appt 将是最近打开的约会项目

      【讨论】:

      • 有一个问题:宏只工作一次。如果我添加第二个约会,除非我再次运行 Application_Startup,否则什么都不会发生。为什么?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-14
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多