Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass Outlook Data to txt file..

Status
Not open for further replies.

ecugrad

MIS
Apr 17, 2001
191
US
Question: I have a template which is filled out by indivuals. Before the email is sent I strip the data out EX:
Requestor: jack splash>, <Phone: 441-2233>, <Fax: 222-222-222>, <MailCode: 100-200-01-02>, <Account: 1212121212111111>, <Note: 00010>, <Forms: CRCM>

When the email is received I need to have it placed in a txt file on my machine to upload into a tracking program. We get around 400 emails a day.

Can somebody help me write the vba into outlook to do this? Everybody says it's easy, but I'm lost..
Will compensate if need be..

Thanks,

Mike



 
You'll need a construction like:

Private Sub Application_NewMail()
Dim myFolder As Outlook.MAPIFolder
Set myFolder = Application.GetNamespace(&quot;MAPI&quot;).GetDefaultFolder(olFolderInbox)
open &quot;MyLog.txt&quot; for append as #1
print#1, myfolder.items(1).body
close#1
End Sub

You'll most likely need to do some more checking (to see if the mail item is of the right type) and some parsing/formatting, but that's the main structure.
Rob
[flowerface]
 
Rob, I set-up a folder and txt doc on the machines C:drive called c:\Mylog\temp.txt and changed
open &quot;MyLog.txt&quot; for append as #1 to open &quot;c:\MyLog\temp.txt&quot; for append as #1. I put the code in a module, but I'm not passing anything to the txt file. If possible can you give me a little more help on this.

Thanks for the time..

Mike
 
Does the code actually get to your file handling statements (confirm by inserting breakpoint)? Does the Myfolder.items(1).body contain anything? Does the file get created and stay empty, or does it not get created at all?
Rob
[flowerface]
 
The file is noting getting created at all, I put the breakpoint on Print #1, myFolder.Items(1).Body, like you asked.
Thanks


Private Sub Application_NewMail()
Dim myFolder As Outlook.MAPIFolder
Set myFolder = Application.GetNamespace(&quot;MAPI&quot;).GetDefaultFolder(olFolderInbox)
Open &quot;c:\MyLog\temp.txt&quot; For Append As #1
Print #1, myFolder.Items(1).Body
Close #1
End Sub
 
I'm not clear what your previous post means - did you solve the problem? If not, did the code break in the right place? Does the message body contain anything?
Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top