
Scheduled task to empty Outlook deleted items
Until someone who has the correct answer replies here is a script I was
playing with to delete certain items from my sent mail. You can try and
modify it to see if it does what you want it to do. :-) You just have to
adjust the "to" items below to get this to work as is. :-)
I did get some errors with this script when it looped through and hit a
meeting confirmation
Option Explicit
Dim fso, wshshell
Set wshshell=WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
wshshell.AppActivate ("Microsoft Outlook")
' If wshshell.AppActivate ("Microsoft Outlook") Then
' else
' wshshell.run Chr(34)&"c:\Program Files\Microsoft
Office\Office10\OUTLOOK.EXE"&Chr(34)
' End if
WScript.Sleep 5000
Dim objOutlook
Dim objNameSpace
Dim objFolder
Dim MyItems
Dim CurrentAppointment
Dim strOutput
Const olMailItem = 0
Const olTaskItem = 3
Const olFolderTasks = 13
Const olFolderSentItems = 5
Dim count, item,i,counter
count = 0
On Error Resume next
'Create Outlook, Namespace, Folder Objects and Task Item
Set objOutlook = createObject("Outlook.application")
Set objNameSpace = objOutlook.GetNameSpace("MAPI")
Set objFolder = objNameSpace.GetDefaultFolder(olFoldersentitems)
'Set MyItems = objFolder.Items
For i = 1 To objFolder.items.count
counter = counter +1
If Err.Number <> 0 Then
MsgBox Err.Number & Err.Description
Err.Clear
Else
If objFolder.Items(i).to = "'someone'" or objFolder.Items(i).to
= "'someone,else'" or objFolder.Items(i).to = "'another person'" or
objFolder.Items(i).to = "'yikes another one'" or objFolder.Items(i).to =
"Don't you keep anything" or objFolder.Items(i).to = "wow" or
objFolder.Items(i).to = "more"or objFolder.Items(i).to = "about time" Then
objFolder.Items(i).delete
count = count + 1
End If
End If
Next
MsgBox "messages moved to deleted = " &count &" counter = "
&counter
Quote:
> As the subject says I'm looking for a way to empty the deleted items in
> Outlook on a schedule. I prefer a script in the .VBS fashion as I'm
trying
> to get some more hands-on experience with it. I would also like to be
able
> to run it without Outlook being open/connected to the Exchange server.
> Any suggestions/guidance is much appreciated!
> THANKS!
> Ken Chapin