PDA

View Full Version : Read subject line and copy mail data in text file



mji
06-07-2014, 03:33 AM
Dear All,

Please provide solution that VBA to read multiple criteria in subject line of email and copy mail data in the text file

i.e. Criteria "DEAL1" "DEAL2" "DEAL3" ++++

Also delete email if its already copied in text file.

Regards.

MJI

Charlize
06-13-2014, 02:00 AM
you need to explain it a bit more ...

1. Give example of such an email in text or mailmessage attached
2. Textfile on a drive ?
3. Append to the end of the textfile ?
4. Format of textfile or just info seperated with special character
5. How do you want to delete mail ? mark it after copied to textfile, move, save to disk, ...
6. ???

Do you already tried something ...

Charlize

westconn1
06-14-2014, 02:34 AM
s = mailitem.subject
criteia = array("DEAL1", "DEAL2", "DEAL3")
mymatch = true
for i = 0 to ubound(criteria)
if instr(s, criteria(i)) = 0 then mymatch = false : exit for
next
if mymatch then
f = freefile
open "c:\somefolder\" & s & ".txt" for output as f
print #f mailitem.body
close f
mailitem.delete
end ifthis can easily be built into a loop to process all mailitems in a folder, does not take any account of any attachments that may exist
the mailitem will be saved to a new text file, with subject as name, change to suit, change folder to suit
the criteria array can be created any way you like, to modify the number of criteria to match, any criteria missing, the mailitem will be ignored
does not check if text file already exists for this mailitem

mji
06-16-2014, 06:30 AM
s = mailitem.subject
criteia = array("DEAL1", "DEAL2", "DEAL3")
mymatch = true
for i = 0 to ubound(criteria)
if instr(s, criteria(i)) = 0 then mymatch = false : exit for
next
if mymatch then
f = freefile
open "c:\somefolder\" & s & ".txt" for output as f
print #f mailitem.body
close f
mailitem.delete
end ifthis can easily be built into a loop to process all mailitems in a folder, does not take any account of any attachments that may exist
the mailitem will be saved to a new text file, with subject as name, change to suit, change folder to suit
the criteria array can be created any way you like, to modify the number of criteria to match, any criteria missing, the mailitem will be ignored
does not check if text file already exists for this mailitem


Thanks for your reply can you please provide complete code as I am new in VBA

Regards.
MJI

westconn1
06-16-2014, 02:21 PM
please provide complete codewe happy to help you with coding, but you need the complete job done, you should be looking for professional assistance, within your local area, rentacoder or similar

in many cases we can not test if the code will work correctly in your environment, so even a complete code may not work correctly
also (and probably most importantly) you have not provided enough information to provide a complete code

if you provide more infomation, like the folder that contains the emails, folder to save texts to, if you want separate text files for each email etc, you might get a complete code, but all of us like some attempts, even from noobies, this is probably a task you are being paid to do? yet you expect someone else to do for yo