Thumper63
2009-11-03 10:08:29 UTC
Hi All!
Am an absolute newbie at this. I've spent quite a bit of time trying
to work this out ... Here's what I've managed so far ... Any help
surely appreciated here.
Option Explicit
Sub ClearOtherInbox()
Dim objFolder As Outlook.Folder
' On Error Resume Next
Set objFolder = GetOtherUserInbox("***@test.com")
Call ProcessFolder(objFolder)
End Sub
Sub ProcessFolder(StartFolder As Outlook.Folder)
' Dim objFolder As Outlook.Folder
' On Error Resume Next
' process all the subfolders of this folder
For Each StartFolder In StartFolder.Folders
Call DeleteFolderItems(StartFolder)
Next
Set StartFolder = Nothing
End Sub
Sub DeleteFolderItems(foldar As Outlook.Folder)
Dim colItems As Outlook.Items
Dim longCount As Long
Dim i As Long
Set colItems = foldar.Items
For i = longCount To 1 Step -1
colItems(i).Delete
Next
Set colItems = Nothing
End Sub
Function GetOtherUserInbox(strUserSMTP As String) As Folder
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.Folder
Dim objMsg As Outlook.MailItem
Dim objRecip As Outlook.Recipient
' On Error Resume Next
Set objOL = Application
Set objNS = objOL.Session
Set objRecip = objNS.CreateRecipient(strUserSMTP)
Set objFolder = objNS.GetSharedDefaultFolder(objRecip,
olFolderInbox)
If objFolder Is Nothing Then
MsgBox "Could not find Inbox for """ & _
strUserSMTP & """", vbExclamation, _
"User Not Found"
End If
Set GetOtherUserInbox = objFolder
Set objFolder = Nothing
Set objRecip = Nothing
Set objMsg = Nothing
Set objNS = Nothing
Set objOL = Nothing
End Function
Am an absolute newbie at this. I've spent quite a bit of time trying
to work this out ... Here's what I've managed so far ... Any help
surely appreciated here.
Option Explicit
Sub ClearOtherInbox()
Dim objFolder As Outlook.Folder
' On Error Resume Next
Set objFolder = GetOtherUserInbox("***@test.com")
Call ProcessFolder(objFolder)
End Sub
Sub ProcessFolder(StartFolder As Outlook.Folder)
' Dim objFolder As Outlook.Folder
' On Error Resume Next
' process all the subfolders of this folder
For Each StartFolder In StartFolder.Folders
Call DeleteFolderItems(StartFolder)
Next
Set StartFolder = Nothing
End Sub
Sub DeleteFolderItems(foldar As Outlook.Folder)
Dim colItems As Outlook.Items
Dim longCount As Long
Dim i As Long
Set colItems = foldar.Items
For i = longCount To 1 Step -1
colItems(i).Delete
Next
Set colItems = Nothing
End Sub
Function GetOtherUserInbox(strUserSMTP As String) As Folder
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.Folder
Dim objMsg As Outlook.MailItem
Dim objRecip As Outlook.Recipient
' On Error Resume Next
Set objOL = Application
Set objNS = objOL.Session
Set objRecip = objNS.CreateRecipient(strUserSMTP)
Set objFolder = objNS.GetSharedDefaultFolder(objRecip,
olFolderInbox)
If objFolder Is Nothing Then
MsgBox "Could not find Inbox for """ & _
strUserSMTP & """", vbExclamation, _
"User Not Found"
End If
Set GetOtherUserInbox = objFolder
Set objFolder = Nothing
Set objRecip = Nothing
Set objMsg = Nothing
Set objNS = Nothing
Set objOL = Nothing
End Function