I'm not familiar in programming in VBA Outlook (2000), so I am searching for
an easy way to create a macro that does the following actions:
- read out the address of the selected email
- put the address to the junk-mail-addresses-list
- delete the mail (because there's no use for junk-mails ;)!!!)
In MS Word there is a recording function for macros, but I couldn't find
such a function in MS Outlook.
Did anyone solve such a problem before? Or maybe: is there anyone who can
tell me how to this? Maybe you can tell me how to work with the required
objects (like: Outlook.Application.....)?
It's not that I am not willing to learn, but I don't know where to start or
find help!
Best regards and thanx for helping me,
Christian
Private Sub Application_NewMail()
Set olMAPI = GetObject("", "Outlook.Application").GetNamespace("MAPI")
Set myItem = olMAPI.GetDefaultFolder(6)
Set Newest = myItem.Items.GetFirst
If Left(myItem.Items.GetFirst.Subject, 11) = "FIF(visual)" Then
Newest.UnRead = False
Newest.Delete
'MsgBox "Message deleted"
ElseIf Left(Newest.Subject, 9) = "SPC ALARM" Then
Newest.UnRead = False
Else:
'MsgBox myItem.Items.GetFirst.Subject
'myItem.Items.GetFirst.UnRead = False
End If
End Sub
HTH, Greg
"Christian Hülsmeier" <hue...@nef.wh.uni-dortmund.de> wrote in message
news:10116303...@emil.nef.wh.uni-dortmund.de...
It is possible to read incoming e-mail addresses and do things with it -
Outlook actually comes with a Junk Mail filter built in, although it is not
very good. You can use VBA to read and write from the text file that
Outlook uses to store the list of Junk Senders e-mail addresses - the
problem is that Outlook locks the file when it is open so you cannot access
it.
Again it is easy to delete a mail item in VBA oItem.Delete once you have got
a handle to the required item.
I suggest you have a dig about on the web and find some Outlook VBA
tutorials and read up a bit then fire any specific questions back to the
group. www.slipstick.com is a good place to start
"Christian Hülsmeier" <hue...@nef.wh.uni-dortmund.de> wrote in message
news:10116303...@emil.nef.wh.uni-dortmund.de...
Here's some code I found on Google Groups a while ago. It didn't work
as written, but I made some modifications to fix it. Seems to work
pretty well now.
Sub KillSpam()
Dim myOlApp As Outlook.Application
Dim myFolder As Outlook.MAPIFolder
Dim myItem As Outlook.MailItem
Dim ctl As CommandBarControl ' Junk E-mail flyout menu
Dim subctl As CommandBarControl ' Add to Junk Senders list menu
item
Dim i As Integer
Set myOlApp = CreateObject("Outlook.Application")
Set myFolder = myOlApp.ActiveExplorer.CurrentFolder
iCount = myOlApp.ActiveExplorer.Selection.Count
For i = 1 To iCount
Set myItem = myOlApp.ActiveExplorer.Selection.Item(1)
Set ctl = myOlApp.ActiveExplorer.CommandBars.FindControl(Type:=msoControlPopup,
ID:=31126)
Set subctl = ctl.CommandBar.Controls(1)
subctl.Execute
myItem.UnRead = False
myItem.Delete
DoEvents
Next i
MsgBox i - 1 & " messages deleted as SPAM.", vbOKOnly, "SPAM
Killed"
End Sub
Hope this helps.