![]() |
|
|
|
#1
|
|||
|
|||
|
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 ---------------------------------------- |
|
#2
|
||||
|
||||
|
Since you're apparently attaching the document to the email, where does the table come from?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
The Table is included in the Word document. It contains a summary of some information contained in the document. Any ideas ? Thanks !
|
|
#4
|
||||
|
||||
|
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#5
|
||||
|
||||
|
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 |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |