vba to copy entire data to email

reza_doang

Board Regular
Joined
May 31, 2010
Messages
187
Hi -

I get VBA macro to copy data in worksheet to email body from rondebruin.
But the code only copy the data and table without charts. Is there any way to copy all the data including charts?


Code:
Sub Mail_Sheet_Outlook_Body()'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
'Don't forget to copy the function RangetoHTML in the module.
'Working in Excel 2000-2013
    Dim rng As Range
    Dim OutApp As Object
    Dim OutMail As Object
    
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    Set rng = Nothing
    'Set rng = ActiveSheet.UsedRange
    'You can also use a sheet name
    Set rng = Sheets("Sheet1").UsedRange

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
        .To = "reza@xxxxxxx.com"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .HTMLBody = RangetoHTML(rng)
        '.Send   'or use
        .Display
    End With
    On Error GoTo 0


Thanks

Reza
 

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.
.
Code:
Option Explicit




Sub mailchart()
Dim OutApp As Object
Dim OutMail As Object
Dim vInspector, GetInspector, wEditor As Variant




Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
    With OutMail
        .To = "yo momma@nowhere.com"
        .CC = "xyz@anc.com"
        .BCC = "abc@xyz.com"
        .Subject = "Test"
        .Body = "Dear" & " Macro " & vbCrLf
        .Display
        ActiveSheet.Range("B2:R21").Copy  '<----- set range to copy here.
        Set vInspector = OutMail.GetInspector
        Set wEditor = vInspector.WordEditor
    
        wEditor.Application.Selection.Start = Len(.Body)
        wEditor.Application.Selection.End = wEditor.Application.Selection.Start
    
        wEditor.Application.Selection.Paste
    
    .Display
    '.Send
    End With
End Sub
 
Upvote 0
.
Code:
Option Explicit




Sub mailchart()
Dim OutApp As Object
Dim OutMail As Object
Dim vInspector, GetInspector, wEditor As Variant




Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
    With OutMail
        .To = "yo momma@nowhere.com"
        .CC = "xyz@anc.com"
        .BCC = "abc@xyz.com"
        .Subject = "Test"
        .Body = "Dear" & " Macro " & vbCrLf
        .Display
        ActiveSheet.Range("B2:R21").Copy  '<----- set range to copy here.
        Set vInspector = OutMail.GetInspector
        Set wEditor = vInspector.WordEditor
    
        wEditor.Application.Selection.Start = Len(.Body)
        wEditor.Application.Selection.End = wEditor.Application.Selection.Start
    
        wEditor.Application.Selection.Paste
    
    .Display
    '.Send
    End With
End Sub

thanks Logit, is working perfectly.
 
Upvote 0

Forum statistics

Threads
1,213,533
Messages
6,114,179
Members
448,554
Latest member
Gleisner2

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