Automate creation of subfolders

  • Thread starter Thread starter Angie
  • Start date Start date
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.
 
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
 
Back
Top