Word -> Outlook Email Body

beczer

New Member
Joined
Nov 21, 2016
Messages
49
Hi everyone

I'm new here and VBA beginner but I need to create something what is too advanced for me at this moment. So I hope you can help me.

So what I need:

I want to create a Macro which Export Part of Word Content (Text and Tables) into Outlook Email body. So I think that I have to use Bookmarks in Word as a reference and probably generate HTML tables.

Every hint, advise will be valuable for me.

Thank you in advance !

Tom
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
This version attempts to find out what is going wrong:

Code:
' Excel module
Sub CreateMail()
Dim objOutlook As Object, objMail As Object, rngTo As Range, rngSubject As Range, wdapp, editor, _
rngAttach As Range, ws As Worksheet, rng1, wdoc, bmk, insp As Inspector
On Error Resume Next
Set wdapp = GetObject(, "Word.Application")                         ' Word already open
On Error GoTo 0
If wdapp Is Nothing Then
    MsgBox "No instances of Word found"
    Exit Sub
End If
wdapp.Visible = 1
Set wdoc = wdapp.ActiveDocument                                     ' desired Word document
Set bmk = wdoc.Bookmarks("bm2")
bmk.Range.Copy
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
Set ws = Worksheets("Sheet1")
With ws
    Set rngTo = .[B1]
    Set rngSubject = .[B2]
    Set rngAttach = .Range(.[b4], .Cells(Rows.Count, "B").End(xlUp))
End With
With objMail
    Set insp = .GetInspector
    If Not insp.IsWordMail Or insp.EditorType <> olEditorWord Then
        MsgBox "This code will not work for you", vbCritical
        Exit Sub
    End If
    .To = rngTo
    .Subject = rngSubject
    Set editor = insp.WordEditor
    editor.Content.Paste                                            ' from bookmark
    For Each rng1 In rngAttach.Cells
        If Len(Dir(rng1)) > 0 Then .Attachments.Add rng1.Value
    Next
    .Display
End With
'wdoc.Close
Set objOutlook = Nothing:   Set objMail = Nothing
Set rngTo = Nothing:        Set rngSubject = Nothing
Set rngAttach = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top