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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
.
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,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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