Results 1 to 6 of 6

Thread: Outlook automation problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    80

    Outlook automation problem

    I am trying to write an automation that will delete the deleted files in the deleted items folder in outlook.....

    Here is the code.

    Private Sub Command1_Click()
    Dim objOutlook As New Outlook.Application
    Dim objNameSpace As Outlook.NameSpace
    Dim objInbox As MAPIFolder
    Dim objMail As MailItem

    'Get the MAPI reference
    Set objNameSpace = objOutlook.GetNamespace("MAPI")

    'Pick up the Inbox
    Set objInbox = objNameSpace.GetDefaultFolder(olFolderDeletedItems)

    'Loop through the folders under the Inbox
    For Each objMail In objInbox.Items
    objMail.Delete
    Next objMail

    End Sub

    I get a code error when it gets to a certain part in the folder....

    Type mismatch - error 13

  2. #2
    On what line?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    80
    Next objMail

    The problem is in the loop......i think

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    80
    Some times it's on the for each statment

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    80
    Figured it out take away Dim objMail As MailItem

    and add
    Set objMail = objOutlook.CreateItem(olMailItem)

    That will take care of it.....My problem now is that it stops for some reason.....

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Posts
    80
    Halfway through deleting all of the e-mails it drops out of the loop.....

    Is there something wrong with my loop?

Posting Permissions

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



Click Here to Expand Forum to Full Width