Automate creation of subfolders

A

Angie

As a step towards our spam blocking, we'd like to create
a folder in everone's mailbox to filter spam into (for
instance, a subfolder of the Inbox named Spam).

How would we go about implementing this? Not sure where
to begin...

Any pointers would be great.
 
K

Ken Slovak - [MVP - Outlook]

Sub CreateSpamFolder()
Dim oFolder As Outlook.MAPIFolder
Dim oInbox As Outlook.MAPIFolder
Dim oFolders As Outlook.Folders
Dim oNS As Outlook.NameSpace
Dim oOL As Outlook.Application

On Error Resume Next

Set oOL = CreateObject("Outlook.Application")
Set oNS = oOL.GetNamespace("MAPI")
Set oInbox = oNS.GetDefaultFolder(olFolderInbox)
Set oFolders = oInbox.Folders
Set oFolder = oFolders.Item("Spam")
If oFolder Is Nothing Then
Err.Clear
Set oFolder = oFolders.Add("Spam")
End If

'set all objects = Nothing here
End Sub

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top