vba to copy entire data to email

reza_doang

Board Regular
Joined
May 31, 2010
Messages
185
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
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
3,352
.
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
 

reza_doang

Board Regular
Joined
May 31, 2010
Messages
185
.
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,849
Messages
5,489,239
Members
407,682
Latest member
gmb2521

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top