获取当前选择的 Outlook 约会

Get the currently selected Outlook Appointment

我想在 Outlook 中有一个按钮,用于将所选 Outlook 约会(在日历 window 中)的类别更改为 'Green Category'。

Sub set_to_solved()
    Dim objApp As Outlook.Application
    
    Dim citem As Outlook.AppointmentItem
    
    citem.Categories = "Green Category"
    
End Sub

我想我没有引用所选项目。

使用 Explorer.Selection property which returns a Selection object that contains the item or items that are selected in the explorer window. The location of a selection in the explorer can be in the view list, the appointment list or task list in the To-Do Bar, or the daily tasks list in a calendar view. For more information, see the Location 属性.

Sub GetSelectedItems() 
 Dim myOlExp As Outlook.Explorer 
 Dim myOlSel As Outlook.Selection 
 Dim oMail As Outlook.AppointmentItem
 Dim oPA As Outlook.PropertyAccessor 
 
 Set myOlExp = Application.ActiveExplorer  
 Set myOlSel = myOlExp.Selection 
 
 Dim MsgTxt as String

 For x = 1 To myOlSel.Count  
  If myOlSel.Item(x).Class = OlObjectClass.olAppointment Then 
  ' For appointment item, use the Organizer property. 
  Set oAppt = myOlSel.Item(x) 
  MsgTxt = oAppt.Organizer 
 Next
 
 Debug.Print MsgTxt 
 
End Sub

首先,你从来没有初始化 citem 有价值的东西,其次,你在设置 Categories 属性 后从未保存约会。

dim citem As object
for each citem in Application.ActiveExplorer.Selection
  if citem.Class = 26 Then 'olAppointment 
    citem.Categories = "Green Category"
    citem.Save
  End If
next