Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 15th, 2008, 06:20 PM
Registered User
 
Join Date: Feb 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default text file in the body of e-mail

I have this third party software that sends e-mails on our behalf. however these e-mail are attachments and alot of companys block attachments. So far im able to loop through the outbox and take the attachment and save them, however i need to copy and paste the text file in the body of the outlook e-mail.
 here is the code I have so far all i need to do is figure out how to copy and paste the text content on the text file into the e-mail.
Thanks in advance and sorry if this dosent belong on this post.

[code]
Public Sub Attach()


 Dim ns As NameSpace
 Dim Outbox As MAPIFolder
 Dim Item As Object
 Dim Atmt As Attachment
 Dim FileName As String
 Dim i As Integer





    Set objWSHShell = CreateObject("WScript.Shell")
    Set ns = GetNamespace("MAPI")
    Set Outbox = ns.GetDefaultFolder(olFolderOutbox)

            i = 0

If Outbox.Items.Count = 0 Then
    MsgBox "There are no messages in the Outbox.", vbInformation, _
           "Nothing Found"
    Exit Sub
 End If

For Each Item In Outbox.Items

    For Each Atmt In Item.Attachments
       FileName = "C:\Email Attachments\" & Atmt.FileName
       Item.Display
       Atmt.SaveAsFile FileName
       Atmt.Delete
       objWSHShell.Run ("notepad.exe Attach.txt") 'here i call the the notepad file to open
       Item.Send
       i = i + 1
    Next Atmt
 Next Item


If i > 0 Then
    MsgBox "I found " & i & " attached files." _
       & vbCrLf & "I have saved them into the C:\Email Attachments folder." _
       & vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
 Else
    MsgBox "I didn't find any attached files in your mail.", vbInformation, _
    "Finished!"
End If

getattachments_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Exit Sub

GetAttachments_err:
   MsgBox "An unexpected error has occurred." _
      & vbCrLf & "Please note and report the following information." _
      & vbCrLf & "Macro Name: GetAttachments" _
      & vbCrLf & "Error Number: " & Err.Number _
      & vbCrLf & "Error Description: " & Err.Description _
      , vbCritical, "Error!"
   Resume getattachments_exit


End Sub

[\code]

 
Old May 1st, 2008, 09:18 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

One Option would be to read the Text file and get the contents stored in the string (http://vbadud.blogspot.com/search?q=Read+Text+Files).

Sub Read_text_File()

Dim oFSO As New FileSystemObject
Dim oFS


Set oFS = oFSO.OpenTextFile("c:\textfile.TXT")

Do Until oFS.AtEndOfStream
sText = oFS.ReadAll
Loop


End Sub

No you can append the String sText to the Body of the eMail item.

http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
body text not inserting Jamessaep BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 April 14th, 2008 02:45 PM
open text and add to outlook body mlov83 BOOK: Professional Outlook 2007 Programming ISBN: 978-0-470-04994-5 0 February 16th, 2008 08:48 AM
Send Mail from Word with formatted Body saimen Excel VBA 1 February 10th, 2005 07:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.