Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook 2003 emtpy folder

Status
Not open for further replies.

djwatts

Programmer
Nov 10, 2004
91
GB
Hi,

does anyone know of a way to permanently delete all of the items in a folder, not send to trash. Like what happens when you hold shift and press delete??

Thanks
 
Hi, again

Just looked at the subject of your post - I guess you meant a PST folder, not a disk folder. Sorry, pls disregard mine.

Jock
 
Sorry, meant an actual outlook folder within outlook 2003 i/e folders\EmailAlerts\

you have to reference them as objects
 

Code:
Sub DeleteFromFolder(ByVal WhichFolder As Long)

Dim objOutlook As Object
Dim objNSpace As Object
Dim objFolder As Object
Dim objItem As Object

    Set objOutlook = CreateObject("Outlook.Application")
    Set objNSpace = objOutlook.GetNamespace("MAPI")
    Set objFolder = objNSpace.GetDefaultFolder(WhichFolder)
    'Listed below all FolderTypeEnumerators
    ' 9 | olFolderCalendar
    '10 | olFolderContacts
    ' 3 | olFolderDeletedItems
    '16 | olFolderDrafts
    ' 6 | olFolderInbox
    '11 | olFolderJournal
    '12 | olFolderNotes
    ' 4 | olFolderOutbox
    ' 5 | olFolderSentMail
    '13 | olFolderTasks
    For Each objItem In objFolder.Items
        objItem.Delete
    Next
    Set objFolder = Nothing
    Set objNSpace = Nothing
    Set objOutlook = Nothing

End Sub
 
Have you tried the Remove method of the MAPIFolder.Items collection instead of the Delte method of the MailItem object ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi the problem i'm having is referencing the correct folder in outlook.

In my pst file there is all of the above folders (shown in code above) + one called folders, which contains sub folders i.e Important, emailAlerts, etc.

Its because I get so many e-mail alerts I just want to be able to click a button and empty the folder
 
If this is the structure of your Folder list

OutlookToday
|
|+Inbox
|+DeletedItems
|+ .
|+ .
|+ .
Personal
|
|+DeletedItems
|+emailAlerts


Code:
Sub RemoveFrom_emailAlerts()

Dim objOutlook As Object
Dim objNSpace As Object
Dim objFolder As Object
Dim objSubFolder As Object

    Set objOutlook = CreateObject("Outlook.Application")
    Set objNSpace = objOutlook.GetNamespace("MAPI")
    Set objFolder = objNSpace.Folders.Item("Personal")
    Set objSubFolder = objFolder.Folders.Item("emailAlerts")
    While objSubFolder.Items.Count > 0
        objSubFolder.Items.Remove (1)
    Wend
    Set objSubFolder = Nothing
    Set objFolder = Nothing
    Set objNSpace = Nothing
    Set objOutlook = Nothing

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top