Results 1 to 2 of 2
  1. #1
    Star Lounger
    Join Date
    Apr 2002
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Deleting all Mail Items in a folder (2000)

    Hi Im running this code, and i want to delete all the items in the folder CC425 after i have saved the attachment and called psubxml...... but i always seem to have one item left over :-(

    Sub psubGetEmailData()

    Dim olOutlook As Outlook.Application
    Dim ns As Outlook.NameSpace
    Dim fld As Outlook.MAPIFolder
    Dim itm As Object
    Dim MyMail As Outlook.MailItem
    '-----------


    Application.ScreenUpdating = False


    Set olOutlook = CreateObject("Outlook.Application")
    Set ns = olOutlook.GetNamespace("MAPI")
    Set itm = ns.GetDefaultFolder(olFolderInbox)
    Set itm = itm.Folders("CC425")

    For Each MyMail In itm.Items
    MyMail.Attachments.Item(1).SaveAsFile "H:TEMP1.xml"
    psubReadandWriteXML
    Next

    For Each MyMail In itm.Items
    MyMail.Delete
    Next


    Set olOutlook = Nothing
    Set ns = Nothing
    Set itms = Nothing
    Set MyMail = Nothing

    End Sub

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Deleting all Mail Items in a folder (2000)

    Try the deletion code this way:

    For Counter = itm.Items.Count To 1 Step -1
    itm.Items(Counter).Delete ' this line may be a bit off, check VBA Help
    Next Counter
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •