2015-10-10 48 views
1

我爲Outlook 2010編寫了一個VBA腳本。此腳本的目的是從用戶的任務和聯繫人中清除一些元素。這需要在遷移到新的客戶端管理解決方案後完成。由於Exchange連接到新解決方案,因此某些項目會翻倍,因此我們需要從Outlook中刪除項目。理想情況下,這將在Exchange服務器上完成,但我們無法直接訪問它...Outlook 2010 VBA腳本部署

我的腳本已經工作,但我的問題在於所述腳本的分佈。我們沒有直接訪問這些人的電腦,所以我們需要的是一種將它打包下載的方式,讓他們從電子郵件中的鏈接運行一次,然後忘掉它。這些用戶中的大多數具有大約零電腦知識。理想情況下,我不希望這個腳本在一次執行後保留在Outlook中。

我搜索了一個解決方案,但什麼也沒發現......

這裏是我的腳本是否有幫助。另外,我不是一個好的程序員......所以如果有更好的方法來做到這一點,不要猶豫,告訴我。

Private Sub CleanUp() 
Dim TaskFolder As Folder 
Set TaskFolder = Session.GetDefaultFolder(olFolderTasks) 
Dim Task As TaskItem 
Dim objProperty As Outlook.UserProperty 
Dim uProperty As String 
Dim collTasks As New Collection 

Dim ContactFolder As Folder 
Set ContactFolder = Session.GetDefaultFolder(olFolderContacts) 
Dim Contact As ContactItem 
Dim objPropertyCLS As Outlook.UserProperty 
Dim uPropertyCLS As String 
Dim collContacts As New Collection 

uProperty = "crmxml" 
uPropertyCLS = "crmLinkState" 

For Each Task In TaskFolder.Items 
    Set objProperty = Task.UserProperties.Find(uProperty, Outlook.OlUserPropertyType.olText) 
    If objProperty Is Nothing Then 
     Debug.Print "objProperty is Nothing" 
    ElseIf InStr(objProperty, "phonecall") > 0 Then 
      collTasks.Add Task 
    ElseIf InStr(objProperty, "letter") > 0 Then 
     collTasks.Add Task 
    ElseIf InStr(objProperty, "fax") > 0 Then 
     collTasks.Add Task 
    End If 
Next 

For Each Contact In ContactFolder.Items 
    Set objPropertyCLS = Contact.UserProperties.Find(uPropertyCLS, Outlook.OlUserPropertyType.olNumber) 

    If objPropertyCLS Is Nothing Then 
     Debug.Print "objPropertyCLS is Nothing" 
    ElseIf Not objPropertyCLS Is Nothing Then 
     collContacts.Add Contact 
    End If 
Next 

For Each Task In collTasks 
    Task.Delete 
Next 

For Each Contact In collContacts 
    Contact.Delete 
Next 
End Sub 

非常感謝!

+0

*所以如果有更好的方法可以做到這一點,請不要猶豫,告訴我。* - 這就是[codereview.se]的用途,你有沒有試過? –

回答

1

VBA腳本不適用於在多臺PC上部署它們。如果您需要在多臺PC上運行您的代碼,則必須改爲開發一個加載項。用戶可以像任何其他Windows程序一樣輕鬆地安裝插件。如果加載項不再需要,可以從Outlook的COM加載項對話框中卸載或禁用該加載項。請參閱Walkthrough: Creating Your First VSTO Add-In for Outlook快速入門。