Wheather Girl,
I have now got the code to save the emails to disk from Outlook, it is
only a couple of lines of code. However, there are a few other things
to consider so I need to ask a few more questions.
Just to recap, you will receive (or send) an email where the Subject
line holds the Project code, plus a -R or -S and then the email
reference number. For example :- 08194-R1234 or 09003-R0002 (I'm
assuming the + sign that crept in on one of the numbers in your last
post was a typo). The 08194 or 09003 is the project code and will also
be the name of the folder into which all emails for that project will
be saved.
Q1. The two examples you gave have five digit numbers for the project
code followed by a dash, is this ALWAYS the case or is it possible
that, in the foreseeable future, you could have six digit project
codes (or even four digit codes)? I need to extract this value to
create the folder on disk and it is easier if they are always a fixed
length, a bit more code if they can be a variable length.
Q2. Are you likely to receive replies from your customers for an email
you sent which you would also want to save to disk. When a reply is
received from a previous email, Outlook adds RE: to the start of the
Subject line. Is this likely to happen? If so then we would need to
strip of the prefix before saving the email.
Q3. This then raises another question. What happens if you try to save
an email that has already been saved, either by trying to save an
already saved email again accidentally or by saving an email that has
been returned to you as a reply (and had the RE: bit removed). You
have several options here :-
(a) Overwrite the existing email with the new email (a dangerous
option unless you are sure it is the same email).
(b) Save the email with a different filename, perhaps append an
incrementing number to the end of the filename automatically so, for
example, 08194-R1234.msg would become 08194-R1234+001.msg (or
whatever).
(c) Allow the user to change the filename and then save it to disk
under that new name. An iffy option unless the user knows what they
are doing, they could change the project code part of the filename or
the extension code which would mess the whole thing up somewhat.
(d) Just not allow the email to be saved at all if it has the same
name as an already saved email.
Let me know what you want the code to do under these circumstances.
Q4. Where abouts on your hard disk are you storing these folders (I
assume that you have some already saved to disk). In other words, what
is the root directory of the project folders, this would be something
like :- C:\Projects\08194 or C:\Projects\09003 I will need that to
locate the project folders. Normally I would not 'hard code' this
pathname (that is enter a pathname into the code) because if you ever
changed it, you would need to rewrite the VBA code to get the project
working again. However, for the moment that will be the easiest
option, maybe when it is working we can add a .ini file on your hard
disk to store it (or perhaps store it in the Registry).
Q5. Is the project code ALWAYS a numerical value. I think it would be
advisable to include some checks in the code to ensure that the email
that the user is trying to save is a valid project email and not some
other email that is not related to any project. If the Subject line of
a valid project email always starts with a five digit number, I could
use that information to validate the email before saving it. I would
think that that would be good enough, it is probably rare to get
normal emails with that sort of Subject line.
To answer your other question, yes you can save ANY email in Outlook,
that is received, sent, deleted, etc. You can also highlight a group
of emails together and save them all in one operation.
There is just one other problem (at the moment). I only have Outlook
2003 so I can tell you how to do all this on that version. Outlook
2007, which I believe you are using, is very different. I have been
advised by the Outlook NG that this should work OK in Outlook 2007 but
I will not be able to give you a detailed procedure (which is fairly
complicated) on how to do it. If possible, I would suggest you
initially try this out on a PC that has Outlook 2003 installed. That
would give a chance to test it out and familiarise yourself with the
procedure. If not you will need to work out how to do on Outlook 2007
yourself. This Web site shows how to do it with Outlook 2003 :-
http://blogs.techrepublic.com.com/howdoi/?p=146
and this is how in Outlook 2007 :-
http://msdn.microsoft.com/en-us/library/dd229324.aspx
but don't try anything just yet.
Let me know the answers to these questions and I will post back the
procedure for Outlook 2003.
Peter Hibbs.