[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to copy the contets of a mail and paste them in to a text file programaticallyy

Posted on 2004-04-09
12
Medium Priority
?
218 Views
Last Modified: 2010-04-08
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

0
Comment
Question by:LakshmanaRavula
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
12 Comments
 
LVL 27

Expert Comment

by:jjafferr
ID: 10794057
Hi LakshmanaRavula,

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,
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20940488.html#10735881

Hope this helps

jaffer
0
 

Author Comment

by:LakshmanaRavula
ID: 10794157
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
0
 
LVL 27

Expert Comment

by:jjafferr
ID: 10794268
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
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:LakshmanaRavula
ID: 10794297
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
0
 
LVL 13

Expert Comment

by:stefri
ID: 10794481
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.FileSystemObject")
 
    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(saveToFile, 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
0
 

Author Comment

by:LakshmanaRavula
ID: 10794541
Hi stefri glad to see you again

I'm facing problem to call a function from the macro which i'M preparing
0
 
LVL 13

Expert Comment

by:stefri
ID: 10794552
Post, I will try to make interactive debugging

Stefri
0
 

Author Comment

by:LakshmanaRavula
ID: 10794567
There is a compile error in the function
Variable not defined
and highlighting  ForWriting
in " Set MyFile = fso.OpenTextFile(saveToFile, ForWriting, True)"
0
 
LVL 13

Expert Comment

by:stefri
ID: 10794585
OK,
ForWriting is an integer
Dim ForWriting as Integer
ForWriting = 2

stefri
0
 

Author Comment

by:LakshmanaRavula
ID: 10794595
Ok that's fine .
it has to stop before "TTT" but it is proceeding till the end of the mail
0
 
LVL 13

Accepted Solution

by:
stefri earned 2000 total points
ID: 10794607
savePartOfMail = Mid(theBody, startAt, endAt - startAt)

If you have extra spaces that have to be removed
savePartOfMail = trim(Mid(theBody, startAt, endAt - startAt))

Stefri
0
 

Author Comment

by:LakshmanaRavula
ID: 10794637
Excellent

Thank You
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Changing a few Outlook Options can help keep you organized!
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question