【发布时间】:2015-10-10 16:46:41
【问题描述】:
我为 Outlook 2010 编写了一个 VBA 脚本。该脚本的目的是为用户清除任务和联系人中的一些元素。这需要在迁移到新的客户端管理解决方案后完成。由于 Exchange 已连接到新解决方案,因此某些项目加倍,因此我们需要从 Outlook 中删除这些项目。理想情况下,这将在 Exchange 服务器上完成,但我们无法直接访问它...
我的脚本已经在运行,但我的问题在于所述脚本的分发。我们无法直接访问这些人的计算机,因此我们需要一种将其打包到下载中的方法,让他们从电子邮件中的链接运行一次,然后忘记它。这些用户中的大多数计算机知识几乎为零。理想情况下,我不希望该脚本在执行完一次后保留在 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
非常感谢!
【问题讨论】:
-
如果有更好的方法,请随时告诉我。 - 这就是Code Review 的用途,你试过了吗?
标签: vba deployment outlook outlook-2010