Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-04-2014, 11:40 AM
frlan2a frlan2a is offline Prefilled email with information contained in a Word document Windows 7 64bit Prefilled email with information contained in a Word document Office 2010 64bit
Novice
Prefilled email with information contained in a Word document
 
Join Date: Sep 2014
Posts: 2
frlan2a is on a distinguished road
Default Prefilled email with information contained in a Word document

Hi,

Would anyone be able to help me with this one ? I want to create Macro that would be linked to a button and that will be used to send an email with some information that are contained in a word document.

I essentially want to prefill the email adresses, subject and body of the email. The main difficulty is that the body of the email is a table of variable row in the word document. I was trying to put the information required in formfeilds in the word document, but I don't know if this is the best way to go.

If anyone has any advice or ideas please let me know !

Thanks a lot for your help.


----------------------------------------

Private Sub SendEmail_Click()

Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document

Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save

With EmailItem
.Subject = "Disposition of AIDC Destructive Tests"


.Body = "Email Information" & vbCrLf & _

" Table form the word document here "

.To = "Addresses Contained in the Word Document"
.Importance = olImportanceNormal
.Attachments.Add Doc.FullName
End With

EmailItem.SendMail

Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing

End Sub

----------------------------------------
Reply With Quote
  #2  
Old 09-05-2014, 12:19 AM
macropod's Avatar
macropod macropod is offline Prefilled email with information contained in a Word document Windows 7 64bit Prefilled email with information contained in a Word document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Since you're apparently attaching the document to the email, where does the table come from?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 09-05-2014, 04:30 AM
frlan2a frlan2a is offline Prefilled email with information contained in a Word document Windows 7 64bit Prefilled email with information contained in a Word document Office 2010 64bit
Novice
Prefilled email with information contained in a Word document
 
Join Date: Sep 2014
Posts: 2
frlan2a is on a distinguished road
Default

The Table is included in the Word document. It contains a summary of some information contained in the document. Any ideas ? Thanks !
Reply With Quote
  #4  
Old 09-05-2014, 06:45 AM
macropod's Avatar
macropod macropod is offline Prefilled email with information contained in a Word document Windows 7 64bit Prefilled email with information contained in a Word document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I'm sure there has to be a way of pasting a Word table into an Outlook message programmatically, but I've never used Outlook. That said, the following will output a table's data in tabular format as part of the email body:

Code:
Dim r As Long, c As Long, Rng As Range, StrMsg As String
With EmailItem
  .BodyFormat = olFormatHTML
  .Subject = "Disposition of AIDC Destructive Tests"
   StrMsg = "Email Information" & vbCrLf & vbCrLf
  With Doc.Tables(1).Range
    For r = 1 To .Rows.Count
      For c = 1 To .Columns.Count
        Set Rng = .Rows(r).Cells(c).Range
        Rng.End = Rng.End - 1
        StrMsg = StrMsg & Rng.Text
        If c < .Columns.Count Then
          StrMsg = StrMsg & vbTab
        Else
          StrMsg = StrMsg & vbCr
        End If
      Next
    Next
  End With
  .Body = StrMsg
  .To = "Addresses Contained in the Word Document"
  .Importance = olImportanceNormal
  .Attachments.Add Doc.FullName
End With
Do note that the above will not work with a table having merged/split cells.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 09-05-2014, 07:36 AM
gmayor's Avatar
gmayor gmayor is offline Prefilled email with information contained in a Word document Windows 7 64bit Prefilled email with information contained in a Word document Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The essentially similar thread at https://www.msofficeforums.com/word-vba/22557-how-copy-userform-text-formfield-contents-outlook.html shows how to access the body of an e-mail message, whereupon it can be processed in VBA just like a Word document, within the limitations of what you can have in an Outlook message.

The macro in the thread is a Word macro. It is equally possible to process from Outlook in much the same way, declaring a Word app rather than an Outlook one.

The other thread pastes the whole document, you could equally paste selections or transfer ranges, just like transferring between Word documents.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Prefilled email with information contained in a Word document Word VBA - Save file as a string contained within the word (always same row and leng) RG87 Word VBA 1 05-21-2014 05:39 AM
Word delete page if string is not contained wolfking333 Word VBA 0 06-23-2013 10:02 AM
Prefilled email with information contained in a Word document Repeating Information in Word Document without Forms or VBA? Bill Bisco Word 6 09-03-2012 07:59 PM
How to disable email information in top of email snahtter Outlook 0 05-05-2012 03:57 AM
Merging a Word doc with VB functions contained adamwbrown Word 0 08-13-2008 06:10 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:42 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft