2013-06-18 52 views
0

在Outlook宏中使用AppointmentItem上的Move方法時,我失去了接收更新的能力,因爲它正在創建項目的副本,而不是真正移動它。此行爲導致該項目不再與原始鏈接關聯,因此不會保留項目更新。Outlook VBA AppointmentItem.Move創建副本

我想通過VBA複製您獲得的剪切/粘貼行爲,它能夠保持原始對象並且不會導致更新丟失。

我相信這與GlobalAppointmentID的基礎上搜索周圍,但我一直沒能找到一種方法來實際移動約會。

我使用的代碼如下。 GetFolderFromPath是一個輔助函數,用於從路徑中返回一個文件夾對象,這非常合適。

Sub MoveItem() 
    Dim targetPath As String: targetPath = "\\[email protected]\Calendar\OOFS" 

    If Application.ActiveExplorer.Selection.Count = 0 Then 
     MsgBox ("No item selected") 
     Exit Sub 
    Else 
     Dim targetFolder As Outlook.Folder 
     Set targetFolder = GetFolderFromPath(targetPath) 

     For x = 1 To Application.ActiveExplorer.Selection.Count 
      Dim oSelected As Variant 
      Set oSelected = Application.ActiveExplorer.Selection.Item(x) 

      If oSelected.Class = olAppointment Then 
       Dim NS As NameSpace: Set NS = Application.GetNamespace("MAPI") 
       Dim oAppt As AppointmentItem: Set oAppt = NS.GetItemFromID(oSelected.EntryID) 
       oAppt.Move targetFolder 
       Set oAppt = Nothing 
       Set NS = Nothing 
      End If 
      Set oSelected = Nothing 
     Next x 
     Set targetFolder = Nothing 
    End If 
End Sub 

回答

0

Outlook僅針對默認日曆文件夾處理傳入會議更新/刪除。如果您將預約移至其他文件夾,則收件箱中的會議更新將在默認日曆文件夾中創建一個新約會。

+0

這是不正確的。因爲如果我(在用戶界面中)右鍵單擊日曆約會,選擇剪切,然後將其粘貼到不同的日曆文件夾中(或者只需簡單地單擊並將其拖動到不同的文件夾中),它將使用任何更新這是製作的。 – hdrpunk