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

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
 
M

Michael Bauer

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
 
D

druben55

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
 
M

Michael Bauer

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.
 
D

druben55

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
 
M

Michael Bauer

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.
 
Joined
Jan 16, 2006
Messages
1
Reaction score
0
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top