Emptying Junk E-mail Folder

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Emptying Junk E-mail Folder

Post by armsys » Fri Jan 13, 2006 2:04 am

Is there any (VBScript) trick to empty the Junk E-mail Folder in Outlook 2003?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Jan 13, 2006 4:23 am

Hi Armstrong....

Check out coding from Helen Feddema. Don't have access to my code/books right now, but just google her. See her Sample Code pages. I have used her code in many applications. Her code is VB/VBA but I think will be close enough to VBScript to be helpful. I have not checked her site for a few months/yrs?, but am sure her work is still available.

Can also get a book on Programming with Outlook98 from Amazon for under $5. Introductory, but provides references to most of the Objects that you need to navigate Outlook folders.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Fri Jan 13, 2006 7:55 am

Hi Bob,

My respectable MS Guru, it's my honor to meet you again here. Thanks for your tips. After receving your post hours ago, I googled around and found, of course, Helen Feddema's homepage (http://www.helenfeddema.com/). I didn't find something I want. Yes, it requires a lot of digging.

Even though emptying Junk E-mail can be done by MS script, I still opt for a VBA solution.

Thanks for your help.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Jan 13, 2006 8:23 am

Here you go:

VBSTART
Sub EmptyFolder(FolderName)
Dim Outlook
Dim PersonalFolder
Dim oFolder
Dim Item

Set Outlook = CreateObject("Outlook.Application")
Set PersonalFolder = Outlook.GetNamespace("MAPI").Folders("Personal Folders")
Set oFolder = PersonalFolder.Folders(FolderName)

Do Until oFolder.Items.Count = 0
Set Item = oFolder.Items.GetFirst
Item.Delete
Loop

Set Item = Nothing
Set oFolder = Nothing
Set PersonalFolder = Nothing
Set Outlook = Nothing
End Sub
VBEND
VBRun>EmptyFolder,Junk

Use to empty whichever folder you like - just put the folder name in the VBRun>EmptyFolder line. E.g. to empty your Outbox:

VBRun>EmptyFolder,Outbox
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Fri Jan 13, 2006 8:40 am

Hi Marcus,

Thanks for saving me hours of goggling and digging.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts