View Single Post
 
Old 03-10-2015, 03:56 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,138
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 ofgmayor has much to be proud of
Default

If by 'send it in the same format as it appears in Word', you mean the message body should have the same format, then you are destined to be disappointed. Word document format and html e-mail format are entirely different from one another. You can get it close if you start by formatting the document in Word's web view, but an exact facsimile is unrealistic.

If format is important then mail it as an attachment in PDF format. http://www.gmayor.com/ManyToOne.htm in one to one mode will achieve either a formatted merge to e-mail body or as an attachment (with or without a personalised covering message). The only proviso is that the merge data must be an Excel worksheet (with the e-mail addresses in the records). The BCC is also possible.

Having said that, it is possible to improve on your macro, but there are some anomalies e.g. you have both the Source Document and the Maillist Document set as the activedocument, which seems odd, given that Source is presumably the product of a mail merge to a new document. You will have to explain that one.

Rather than just use the .Body of the message, you need to use the Outlook Inspector to enable you to edit the message body e.g. something along the lines of

Code:
For j = 1 To Source.Sections.Count - 1
        Set oItem = oOutlookApp.CreateItem(olMailItem)
        With oItem
            .BodyFormat = 2
            Set olInsp = .GetInspector
            Set wdDoc = olInsp.WordEditor
            Set oRng = wdDoc.Range
            'If you don't want the default signature, remove the next line
            oRng.Collapse 1
            .Display 'this must not be removed.
            .Subject = mysubject
            oRng.FormattedText = Source.Sections(j).Range.FormattedText
            Set Datarange = Maillist.Tables(1).Cell(j, 1).Range
            Datarange.End = Datarange.End - 1
            .to = Datarange
            .BCC = "amentinho@example.com"
            For i = 2 To Maillist.Tables(1).Columns.Count
                Set Datarange = Maillist.Tables(1).Cell(j, i).Range
                Datarange.End = Datarange.End - 1
                .Attachments.Add Trim(Datarange.Text), olByValue, 1
            Next i
            .Send
        End With
        Set oItem = Nothing
    Next j
is probably not far off (olInsp, wdDoc and oRng are each declared as Object) but without the document to test against it is only a guide.
__________________
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