how do i send a word document as the body of an email in access 2003?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • I7arkHiro97
    New Member
    • Jun 2010
    • 2

    how do i send a word document as the body of an email in access 2003?

    Hi,

    I am a beginner to VBA. I am using MS access 2003. I found some code that works great for sending automatic emails to a list of recipients. My email addresses are housed in a table on access and they are pulled into a query to send an email to only those who are listed in my query.

    Right now the code uses a text document as the body of the email. Is there a way to change the code in order to use a word document instead of a text document? I also wanted to know if its possible to transfer the text and pics from the word document over to the body of the email exactly how it looks. For example if the text is bold or colored, can it tranfer over to look that way in the body of the email? However I did find code that will use a word document as the body of an email on word, I would like to do that but using VBA on access 2003.

    The second thing is that I will be sending an email to a massive list of recipients. I was able to use the code to add all the email addresses to a single email on the TO: recipient from my list of email addresses from my query. Can the code be altered to show all the email addresses as Undisclosed Recipents when the email is sent? The main thing is that I want to ensure the recipients can't see the massive email list of other reciepents. Also if they click the reply to all by accident, I want them to only be able to send a reply back to just the sender.

    Please show me exaclty what I need to change and add, also where to put it. Like I said, I am a beginner in VBA.

    I would really appreciate all the help. Thank you for taking the time

    Here is the code I am using:

    Code:
    Public Function SendEMail()
    
    Dim db As DAO.Database
    Dim MailList As DAO.Recordset
    Dim MyOutlook As Outlook.Application
    Dim MyMail As Outlook.MailItem
    Dim Subjectline As String
    Dim BodyFile As String
    Dim fso As FileSystemObject
    Dim MyBody As TextStream
    Dim MyBodyText As String
    
    Set fso = New FileSystemObject
    Subjectline$ = InputBox$("Please enter the subject line for this mailing.", _
    "We Need A Subject Line!")
    
    If Subjectline$ = "" Then
    MsgBox "No subject line, no message." & vbNewLine & vbNewLine & _
    "Quitting...", vbCritical, "E-Mail Merger"
    Exit Function
    End If
    BodyFile$ = InputBox$("Please enter the filename of the body of the message.", _
    "We Need A Body!")
    If BodyFile$ = "" Then
    MsgBox "No body, no message." & vbNewLine & vbNewLine & _
    "Quitting...", vbCritical, "I Ain??t Got No-Body!"
    Exit Function
    End If
    
    If fso.FileExists(BodyFile$) = False Then
    MsgBox "The body file isn??t where you say it is. " & vbNewLine & vbNewLine & _
    "Quitting...", vbCritical, "I Ain??t Got No-Body!"
    Exit Function
    End If
    Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False, TristateUseDefault)
    MyBodyText = MyBody.ReadAll
    
    MyBody.Close
    Set MyOutlook = New Outlook.Application
    
    Set db = CurrentDb()
    
    Set MailList = db.OpenRecordset("MyEmailAddresses")
    
    Set MyMail = MyOutlook.CreateItem(olMailItem)
    
    Do Until MailList.EOF
    
    MyMail.Recipients.Add = MailList("email")
    
    MailList.MoveNext
    
    Loop
    
    MyMail.Subject = Subjectline$
    
    MyMail.body = "Dear Recipient(s)" & "," & vbNewLine & vbNewLine & MyBodyText
    
    MyMail.Display
    
    Set MyMail = Nothing
    Set MyOutlook = Nothing
    MailList.Close
    Set MailList = Nothing
    db.Close
    Set db = Nothing
    
    End Function
    Last edited by Niheel; Jun 30 '10, 06:13 AM. Reason: please use code tags to display code
  • maxamis4
    Recognized Expert Contributor
    • Jan 2007
    • 295

    #2
    This works for me in vb.net should work in access with the proper references:

    Code:
    Dim oWord As Word.Application
    Dim oDoc As Word.Document
    oWord = CreateObject("Word.Application")
    oWord.Visible = True
    oDoc = oWord.Documents.Open("c:\SomeWordFile.doc", , True)
    oWord.Selection.WholeStory()
    Dim wholeText As String = oWord.Selection.Text

    Comment

    • I7arkHiro97
      New Member
      • Jun 2010
      • 2

      #3
      Originally posted by maxamis4
      This works for me in vb.net should work in access with the proper references:

      Code:
      Dim oWord As Word.Application
      Dim oDoc As Word.Document
      oWord = CreateObject("Word.Application")
      oWord.Visible = True
      oDoc = oWord.Documents.Open("c:\SomeWordFile.doc", , True)
      oWord.Selection.WholeStory()
      Dim wholeText As String = oWord.Selection.Text
      Hey thanks for the info. Can you do a before and after type thing so I can see what the changes were and where into my existing code? Remember, I am a beginner at this. Thanks again for the help.

      Comment

      Working...