Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old February 15th, 2008, 06:20 PM
Registered User
Join Date: Feb 2008
Location: , , .
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.

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
       Atmt.SaveAsFile FileName
       objWSHShell.Run ("notepad.exe Attach.txt") 'here i call the the notepad file to open
       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!"
    MsgBox "I didn't find any attached files in your mail.", vbInformation, _
End If

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

   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


Reply With Quote
  #2 (permalink)  
Old May 1st, 2008, 10:18 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts

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

End Sub

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


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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 03: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

All times are GMT -4. The time now is 12:05 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.