How to???

  • Thread starter Thread starter Mr. Clean
  • Start date Start date
M

Mr. Clean

I neeed to iterate through seleceted items in the main window and send
them to the Junk Senders List.

Where do I begin?
 
You can always turn on the Junk Sender's rule if it comes from a particular source. If you want to creat a Macro with a button on the toolbar then try this.

There are three steps to this:
First open the appropriate folder
Second loop through the messages
Third perform the action based on your criteria

1. This VBA code will retrieve messages in the currently open folder. If you only want it to go to your Inbox change it to
Outlook.GetDefaultFolder.olFolderInbox

Dim MyInbox As Outlook.MAPIFolder
Set MyInbox = Outlook.ActiveExplorer.CurrentFolder 'This will let you manipulate the folder later in the code

2. This part will loop and grab each message in the folder

Dim Message As Outlook.MailItem
Dim NumberOfEmails As Integer, x As Integer
NumberOfEmails = MyInbox.Items.Count

For x = 1 To NumberOfEmails
Set Message = MyInbox.Items(x)
Next X


3. Repost if you need help manipulating the message. Basically it is a matter of comparing the message (e.g. subject, body etc.) to whatever you are looking for.

There may be a better way to do this but I'm pretty new at VBA. A co-worker said it would be faster to create a dynamically sized array, insert the messages into the array, scan them and then move them. I found it easier to code a loop.


Kenneth Romo
LT, USN
 
Back
Top