View Single Post
  #10  
Old March 14th 06, 10:10 PM posted to microsoft.public.outlook.program_vba
Spectre
external usenet poster
 
Posts: 12
Default last solution

Hi,

Thanks for your comments and your help.

For sure the " If oSelection.Count 0 Then" is not necessary!
For the other points :
- i don't select all the items to delete but only one, and it works (it
adds all the adresses in the blocked list and deletes all the mails in
the directory) but... only if I have first deleted a email in the
"ordinary way" and I don't understand why.

If you can help me on this....

Thanks an dbye



Après mûre réflexion, Michael Bauer a écrit :
Am Sun, 12 Mar 2006 12:29:10 +0100 schrieb Spect

Did you test that solution also for the case that really several items are
selected?

As I wrote in your former thread, the button you refer to isn´t enabled if
more than one item is selected.

Additionally the For Next loop doesn´t work if you do have more than one
item in the list and delete them. In that case your loop must count
backwards:

For i=oSelection.Count To 1 Step -1
...
Next

No errors but hopefully useful tipps for you:

For I = 1 To oSelection.Count
Set olItem = oSelection.Item(I)
If oSelection.Count 0 Then ' si il ya de s
mails


If the loop starts, i.e. if the execution goes on with the last line, then
you do know already that Count 0. There´s no need to ask that again.

Set Btn =
Application.ActiveExplorer.CommandBars.FindControl (1, 9786)


The button is always the same. It slows down the execution if you set the
variable within the loop again and again.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.vbOffice.net --


Last release to add spam addresses in the list of blocked addresses. It
deletes also the spams.

Sub addSpamAdress() ' ajoute toutes les adresses des span à la liste
d'expéditeur indésirables
'On Error Resume Next

Dim olItem As Mailitem
Dim objInbox As MAPIFolder
Dim oSelection
Dim arc As Outlook.MAPIFolder
Dim junkMailAddress As String
Dim response As String

Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderJunk)
Set oSelection = objInbox.Items

response = MsgBox("Your are going to add all the email addresses
to the Bocked Email list" & vbCrLf & _
"All emails will be deleted",
vbYesNoCancel, "Junk Mail")

If response = vbNo Or response = vbCancel Then
Exit Sub
Else
For I = 1 To oSelection.Count
Set olItem = oSelection.Item(I)
If oSelection.Count 0 Then ' si il ya de s
mails
junkMailAddress = olItem.SenderEmailAddress
If junkMailAddress "" Then

Set Btn =
Application.ActiveExplorer.CommandBars.FindControl (1, 9786)
Btn.Execute
olItem.Delete

End If
End If
Next
End If
End Sub



Spectre a formulé la demande :
Hi,

Even if spammers use often a new address for each spam they send, it is not
always the case.

Hence, I am looking for a function which could add on one click all the
email addresses of the spams beeing in the unsollicited email folder (a
translation from French for "courrier indésirable")! to the list of
unsollicited mail addresses.
I have tried to do it myself but I have been unable to find the name of
this list.

Thanks



Ads