I wrote a VBA script for Outlook 2010. The purpose of this script is to clean some elements from the tasks and contacts for the user. This needs to be done following a migration to a new client managing solution. Since Exchange is connected to the new solution some items are doubled so we need to delete the items from outlook. Ideally this would be done on the Exchange server but we don't have access to it directly...
My script is already working but my problem lies with the distribution of said script. We don't have direct access to the computers of these people so what we need is a way to package it in a download, have them run it once from a link in an email and forget about it. Most of these users have about zero computer knowledge. Ideally I don't want this script to remain in Outlook after that one execution.
I searched for a solution but found nothing...
Here's my script if that helps. Also, I'm not a good programmer... So if there's a better way to do this don't hesitate to tell me.
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
Thanks a lot!
VBA scripts were not designed for deploying them on multiple PCs. If you need to run your code on multiple PCs you have to develop an add-in instead. Add-ins can be installed by users easily like any other Windows programs. If the add-in is not required any longer, it can be un-installed or disabled from the COM add-ins dialog in Outlook. See Walkthrough: Creating Your First VSTO Add-In for Outlook to get started quickly.