saving an attachment to a particular folder when mail rec'd with a particular subject

  • Thread starter Thread starter Fabio Papa
  • Start date Start date
F

Fabio Papa

Hi,

I am trying to set up outlook to automatically save an attachment to a
particular folder when mail is received and has a particular phrase in the
subject line. I am assuming this is possible with vba. if so, can you
please give me an idea of how to do this. I have used vba in Microsoft
access, so I kind of know the model, but I have no idea how to start this
particular task. if this question is to general, maybe you can point me in
the right direction (like a web site or something) that can teach me how to
do this.

Thanks for your help,



fab
 
Hi Sue,

That really does help, thank you. Both those examples show how to save
attachments from selected e-mails, but is there a way to make it so that
this runs automatically every time new mail is received and only on the new
mail (not the whole inbox and not just on the selected items). Maybe this
is done through a rule? Basically I need to tell outlook: "when subject is
x then save any attachments to this folder."

Thanks again for the help so far.

fabs
 
See http://www.outlookcode.com/d/code/zaphtml.htm for examples of basic
methods of running code automatically, either from a rule or by monitor a
folder for new items.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Hi,

OK, I'm getting there, I think?

I have a rule that looks like this:

-- Apply this rule after the message arrives
-- with _CommuniKate voice message_ in the subject
-- and which has an attachment
-- and on this machine only
-- run _Project1.SaveCommunikateAttachment_
-- and mark it as read
-- and display a Desktop Alert

The code called by the "run" line looks like this:

-- Sub SaveCommunikateAttachment(item As MailItem)
--
-- Dim path As String
-- Dim filename As String
-- path = "F:\Documents and Settings\MyName\My Documents\Communikate\"
-- filename = item.SentOn & " - " & Round((item.Size - 3) / 1.95) _
-- & " second message from " & Mid(item.Subject, 30,
Len(item.Subject) - 30) _
-- & ".mp3"
-- item.Attachments(1).SaveAsFile path & filename
--
-- End Sub

This seems to me that it should work, but it does not. The rule runs (I get
the desktop alert) but I'm not sure that the code is being run or even
called as I don't even get any error messages. These emails I am trying to
run this code on only ever have one attachment, that is why I don't attempt
to loop through the attachments. I know for certain that the folder named
in the code exists. The filename I am attempting to get is the date the
email was sent, a dash, an estimate of how many seconds long the audio file
is, a portion of the subject line, and the ".mp3" extension. Please provide
any insight or ideas you might have. Thanks.

fabs
 
You can check whether the code is running by putting a breakpoint in it.
Have you checked to see whether any VBA code at all runs?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
hmmmm, I set several different breakpoints in the code but nothing happened.
So I guess my code isn't running(?). I tried changing a couple of different
options in outlook regarding running scripts and macros and security
settings, but still nothing. Any sugestions?
 
Did you try running just a little Sub in VBA? If you changed the macro
security level, did you restart Outlook?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Hi Sue,

You were absolutely right about re-starting. After making the macro
security change and restarting outlook, the code ran! Now, after a little
tweeking and debugging, the code you helped me with works wonderfully.
Many, many thanks.

Fabio
 
Hi,

I am doing something very similar and would love to see your code so I don't
have to start from scratch.

Thanks - these newsgroups are very helpful.

dave
 
Back
Top