[OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox
Go Back  Xtreme Visual Basic Talk > > > [OUTLOOK] Remove Email on secondary mailbox


Reply
 
Thread Tools Display Modes
  #1  
Old 08-09-2012, 06:36 AM
Corentin Corentin is offline
Newcomer
 
Join Date: Aug 2012
Posts: 1
Default [OUTLOOK] Remove Email on secondary mailbox


Hello,

I'm trying to automatize the deletion of secondary mailboxes items that are older than 6 days. The problem is that the objFolder and the SI_Items variables didn't initialize correctly in the script below. This script works perfectly if I change it a little bit in order to launch it in my own mailbox.

Can you please help me to find a solution ?

Sub RemoveOldEmails()

Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim SI_Items As Outlook.MailItem
Dim objFolder As Outlook.Folder
Dim myRecipient As Outlook.Recipient

On Error Resume Next

Set objOL = CreateObject("outlook.application")
Set objNS = objOL.GetNamespace("MAPI")

Set myRecipient = objNS.CreateRecipient("TEST-AUD")
myRecipient.Resolve

Set objFolder = objNS.GetSharedDefaultFolder(myRecipient, olFolderInbox)
Set SI_Items = objFolder.Items


For i = SI_Items.Count To 1 Step -1
If TypeName(SI_Items.Item(i)) = "MailItem" Then
If Date - SI_Items.Item(i).ReceivedTime > 6 Then SI_Items.Item(i).Delete
End If
Next

Set olApp = Nothing
Set objNS = Nothing
Set objFolder = Nothing
Set SI_Items = Nothing
Set myRecipient = Nothing
End Sub


Many thanks in advance for your help,

Best regards,

Corentin
Reply With Quote
  #2  
Old 08-09-2012, 09:39 AM
Gruff's Avatar
Gruff[OUTLOOK] Remove Email on secondary mailbox Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Welcome to the forum Corentin. Don't forget to read the forum Posting Guidelines.

If your look at your variable definitions SI_Items is defined as a single mailitem.
objFolder.Items is a collection of mailitems.

Not all that up on Outlook programming so I do not know if there is a MailItems Collection Class or if you can use a general collection.
Further we just stopped using Exchange and Outlook where I work so I cannot test things for you.

In anycase... Why are you bothering with doing this in VBA?
What's wrong with creating a rule in Outlook to automatically handle the situation?
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
[OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox [OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox
 
[OUTLOOK] Remove Email on secondary mailbox
[OUTLOOK] Remove Email on secondary mailbox
 
-->