Results 1 to 4 of 4

Thread: vba to copy entire data to email
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    May 2010
    Posts
    185
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default vba to copy entire data to email

    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

  2. #2
    Board Regular Logit's Avatar
    Join Date
    Aug 2016
    Location
    United States
    Posts
    2,784
    Post Thanks / Like
    Mentioned
    36 Post(s)
    Tagged
    1 Thread(s)

    Default Re: vba to copy entire data to email

    .
    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

  3. #3
    Board Regular
    Join Date
    May 2010
    Posts
    185
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: vba to copy entire data to email

    Quote Originally Posted by Logit View Post
    .
    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.

  4. #4
    Board Regular Logit's Avatar
    Join Date
    Aug 2016
    Location
    United States
    Posts
    2,784
    Post Thanks / Like
    Mentioned
    36 Post(s)
    Tagged
    1 Thread(s)

    Default Re: vba to copy entire data to email

    .
    You are welcome.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •