LakshmanaRavula
asked on
How to copy the contets of a mail and paste them in to a text file programaticallyy
Hi,
I need to copy the contents of a mail and paste them in to a text file and save the text file
I need to do this by writing some macro in Outlook
Suppose My mail contains lot of words
Example of a mail body:
AA BB CC DD EE FF FF GG HH II JJ KK LL MM NNN OOO PPP
QQQ RRR SSS TTT UUUUU VVVVVVV WWWWW XXXXX YYYYY Z
Now I need to copy the contents starts from specified string "GG" (including "GG") and ends before specified string "TTT" (Excluding "TTT")
Then I need to paste the content in to a text file (Notepad) and save it in the required path
Can any body help me please
I need to copy the contents of a mail and paste them in to a text file and save the text file
I need to do this by writing some macro in Outlook
Suppose My mail contains lot of words
Example of a mail body:
AA BB CC DD EE FF FF GG HH II JJ KK LL MM NNN OOO PPP
QQQ RRR SSS TTT UUUUU VVVVVVV WWWWW XXXXX YYYYY Z
Now I need to copy the contents starts from specified string "GG" (including "GG") and ends before specified string "TTT" (Excluding "TTT")
Then I need to paste the content in to a text file (Notepad) and save it in the required path
Can any body help me please
ASKER
Wow lot of code
Thank you Jaffer,
But i think I don't need that much code.
My requirement is very simple.
Now I made a string from a mail with the required text in it
This string has to be copied in to a text file (bY opening a new one)
and save the text file in to the required path and close it
Thank you Jaffer,
But i think I don't need that much code.
My requirement is very simple.
Now I made a string from a mail with the required text in it
This string has to be copied in to a text file (bY opening a new one)
and save the text file in to the required path and close it
Ok LakshmanaRavula
tell me,
will there be only 1 email?
Will this/these emails always have 1 thing in common, like the same subject, OR certain words in the body?
jaffer
tell me,
will there be only 1 email?
Will this/these emails always have 1 thing in common, like the same subject, OR certain words in the body?
jaffer
ASKER
I'm preparing a macro which will fire when ever a new mail arrives and process the mail. as a part of it I need to store certain data in to a text file
Yes as i said to you in my earlier posting "GG" and "TTT" are common words in the body
I need the text between these two strings which will be changing from amil to mail
I need to copy the contents starts from specified string "GG" (including "GG") and ends before specified string "TTT" (Excluding "TTT")
Thank You
Yes as i said to you in my earlier posting "GG" and "TTT" are common words in the body
I need the text between these two strings which will be changing from amil to mail
I need to copy the contents starts from specified string "GG" (including "GG") and ends before specified string "TTT" (Excluding "TTT")
Thank You
LakshmanaRavula
Option Explcit
'Function savePartOfMail(theBody, startWith, endWith, saveToFile) As String
Dim strMsg As String
Dim startAt As Long
Dim endAt As Long
Dim fso As Object, MyFile As Object
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
savePartOfMail = ""
startAt = InStr(1, theBody, startWith, vbTextCompare)
If startAt = 0 Then Exit Function
endAt = InStr(1, theBody, endWith, vbTextCompare)
If endAt = 0 Then Exit Function
Set MyFile = fso.OpenTextFile(saveToFil e, ForWriting, True)
savePartOfMail = Mid(theBody, startAt, endAt)
MyFile.Write savePartOfMail
MyFile.Close
Set MyFile = Nothing
Set fso = Nothing
End Function
call it with
Dim stout as string
dim saveInFile as string
saveInFile ="c:\myPatialMail.txt"
stout = savePartOfMail(theBody, "GG", "TTT", saveInFile)
I output stout just if you would need it in the rest of the code
Stefr
Option Explcit
'Function savePartOfMail(theBody, startWith, endWith, saveToFile) As String
Dim strMsg As String
Dim startAt As Long
Dim endAt As Long
Dim fso As Object, MyFile As Object
Set fso = CreateObject("Scripting.Fi
savePartOfMail = ""
startAt = InStr(1, theBody, startWith, vbTextCompare)
If startAt = 0 Then Exit Function
endAt = InStr(1, theBody, endWith, vbTextCompare)
If endAt = 0 Then Exit Function
Set MyFile = fso.OpenTextFile(saveToFil
savePartOfMail = Mid(theBody, startAt, endAt)
MyFile.Write savePartOfMail
MyFile.Close
Set MyFile = Nothing
Set fso = Nothing
End Function
call it with
Dim stout as string
dim saveInFile as string
saveInFile ="c:\myPatialMail.txt"
stout = savePartOfMail(theBody, "GG", "TTT", saveInFile)
I output stout just if you would need it in the rest of the code
Stefr
ASKER
Hi stefri glad to see you again
I'm facing problem to call a function from the macro which i'M preparing
I'm facing problem to call a function from the macro which i'M preparing
Post, I will try to make interactive debugging
Stefri
Stefri
ASKER
There is a compile error in the function
Variable not defined
and highlighting ForWriting
in " Set MyFile = fso.OpenTextFile(saveToFil e, ForWriting, True)"
Variable not defined
and highlighting ForWriting
in " Set MyFile = fso.OpenTextFile(saveToFil
OK,
ForWriting is an integer
Dim ForWriting as Integer
ForWriting = 2
stefri
ForWriting is an integer
Dim ForWriting as Integer
ForWriting = 2
stefri
ASKER
Ok that's fine .
it has to stop before "TTT" but it is proceeding till the end of the mail
it has to stop before "TTT" but it is proceeding till the end of the mail
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent
Thank You
Thank You
Go to this link, I have done this in Access, but you can remove the Form and Table stuff from it,
It will help you in what you want,
https://www.experts-exchange.com/questions/20940488/Parse-emails-from-Outlook-Express.html#10735881
Hope this helps
jaffer