Newbie seeks help writing macro to empty Outlook junk e-mail folder

  • Thread starter Thread starter druben55
  • Start date Start date
D

druben55

Hi,

This oughta be simple, so I'm hoping someone can just respond w/the VBA
code. I want a macro that will automate this series of 4 keystrokes in
Outlook 2003:

1. Tab (to move focus from folder list to pane w/list of junk emails)
2. Cntl-A (to highlight all junk emails in pane)
3. Cntl-Q (to mark them all as read)
4. Del

I "recorded" such a macro in Word, but can't get it to appear in
Outlook, so I guess I need to write a VBA version within Outlook. Can
anyone help me out?

Many thanks!
David
 
Am 28 Dec 2005 12:55:35 -0800 schrieb (e-mail address removed):


Sample:

Dim oFld as Outlook.MapiFolder
Set oFld=Application.Session.GetDefaultFolder(olFolderJunk)
With oFld
While .Items.Count
.Items(1).Delete
Wend
End With
 
Michael,

Actually, after running this macro a few times, there is one glitch: It
does not seem to be implementing the "ctrl-Q" command to mark all of
the junk emails as read before deleting them. (Thus they show up in my
Deleted Items folder as bolded/unread, which I find annoying.) Any
suggestions?

Thanks much again,
David
 
Am 30 Dec 2005 05:53:07 -0800 schrieb (e-mail address removed):

David, within the While loop set the Unread property = True and call the
Save method before deleting the item.
 
Sorry, Michael, I am completely clueless when it comes to VBA
programming...would you be so kind as to copy the entire sequence with
those modifications included?

With thanks, as ever,
David
 
Am 1 Jan 2006 09:05:23 -0800 schrieb (e-mail address removed):


Sorry, Michael, I am completely clueless when it comes to VBA
programming...would you be so kind as to copy the entire sequence with
those modifications included?

With thanks, as ever,
David

David, this is really very simple and a good point to start your first self
written lines.

Surely you find the loop starting with the "While" statement. After that
insert a new line, enter a dot and start typing the next command "Unread".
You don´t even have to enter all the word due to IntelliSense. Then enter
the '=' character, IntelliSense will provide you now with the both possible
values; select "true" as mentioned.

Now insert another line, enter a dot again and start typing the next
command. That´s it.
 
David,

Here you go.

Sub EmptyJunk()

Dim oFld As Outlook.MAPIFolder
Set oFld = Application.Session.GetDefaultFolder(olFolderJunk)
With oFld
While .Items.Count
.Items(1).UnRead = False
.Items(1).Delete
Wend
End With

End Sub

Cheers,

Bruce
 
Back
Top