Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro to empty junk email folder (2003 XP1)

    Hi all

    I'm not a big macro guru & while I can get by in Word because I can record macros, I don't have a clue how to do it in Outlook.

    I'd like a macro to empty the junk email folder - I'm sure it's very straightforward to someone who knows what they are doing.

    I'd be grateful if anyone could get me started.

    Thanks a lot

    Neil

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to empty junk email folder (2003 XP1)

    You could use this:

    Sub ClearFolder(FolderType As OlDefaultFolders)
    Dim nsp As NameSpace
    Dim fld As MAPIFolder
    Dim i As Integer
    Set nsp = GetNamespace("MAPI")
    Set fld = nsp.GetDefaultFolder(FolderType)
    For i = fld.Items.Count To 1 Step -1
    fld.Items.Remove i
    Next i
    Set fld = Nothing
    Set nsp = Nothing
    End Sub

    Sub ClearJunk()
    Call ClearFolder(olFolderJunk)
    End Sub

    The ClearJunk procedure is the macro you requested.
    The first procedure can be called with any default folder identifier, for example to clear the Deleted Items folder, you'd use

    Call ClearFolder(olFolderDeletedItems)

  3. #3
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to empty junk email folder (2003 XP1)

    Hans

    Once again, thanks very much for your help - this worked perfectly first time!

    Very best regards

    Neil

Posting Permissions

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