PDA

View Full Version : Solved: Automatic Attachment Saves and Deletes



gmillers58
01-19-2006, 01:47 PM
Hello, I have a question. I want to use an Outlook Rule to automatically save incoming Mail attachments to a disk folder. Afterwards, I want to Archive the attachment.

Also I need to look at the SUBJECT line from the "New" incoming Mail for a key word ie;("Save This") so I know the attachment associated with this Mail Item is one I need to save.

Problem 1: What can I use to search the subject line string to see if a particular group of letters exist

Problem 2: How do I avoid not searching the entire inbox, only the most currently arriving piece of mail.

Thanks in Advance
:bug:

Killian
01-22-2006, 09:04 AM
Hi and welcome to VBAX :hi:

This (http://vbaexpress.com/kb/getarticle.php?kb_id=522) kb entry should get you started - you won't need the PrintAttachment part, you'll just need to add something to archive the mailitem. It works with a mail item as it arrives, so you'll just need to get its .Subject property and test for the text you want, something likeIf Instr(Item.Subject, "Save This") <> 0 Then
' do something
End If

gmillers58
01-25-2006, 10:54 AM
Thanks very much, I'll give it a try.

chrismc
01-29-2006, 04:16 AM
Hi guys,

this thread started me off to solve a problem that I had been thinking about for some time and I managed to solve it fairly quickly.

What I have is a folder full of messages and I need to check the subject to identify and then deal with particular messages. The instr solution works fine. However, looking around I have come across .find and .findnext.

Question 1: would .find and .findnext be more efficient coding than using instr?

To use .find and .findnext you need to use a search string and something like this would work to find any subject that starts with Jobserve UK Subscription:
Set myMailItem = myMail.Find("[Subject] >= ""Jobserve UK Subscription"" and [Subject] <= ""Jobserve UK Subscriptiop"" ")

Question 2: How can I use wildcards with .find? I have tried using the 'like' operator as in:

Set currentAppointment = myAppointments.Find("[Subject] like ""Jac*"" ")
but I get an error 'condition is not valid'.

I forgot to ask question 3.

When using find and findnext is there a count? I know I can use something like:




Set myAppointments = myNameSpace.GetDefaultFolder(olFolderCalendar).Items

Set currentAppointment = myAppointments.Find("[Subject] = ""Jac"" ")

While TypeName(currentAppointment) <> "Nothing"

cnt = cnt + 1

Set currentAppointment = myAppointments.FindNext

Wend



And this will tell me how many items match the search ? but there has to be a better way.


Thanks.

Chris