Excel VBA Email more than one range in body using Mail Envelope

Hi

I found the following example at http://www.rondebruin.nl/win/s1/outlook/bmail2.htm
on how to email an Excel range using the mail envelope in Excel VBA.
I need to email two separate ranges one under the other eg C16:D17 and C136:D165
How would I do this?

Note: The worksheet/range not have to be active when you run the code.
Sub Send_Range_Or_Whole_Worksheet_with_MailEnvelope()
'Working in Excel 2002-2013
    Dim AWorksheet As Worksheet
    Dim Sendrng As Range
    Dim rng As Range

    On Error GoTo StopMacro

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    'Fill in the Worksheet/range you want to mail
    'Note: if you use one cell it will send the whole worksheet
    Set Sendrng = Worksheets("Sheet1").Range("A1:B15")

    'Remember the activesheet
    Set AWorksheet = ActiveSheet

    With Sendrng

        ' Select the worksheet with the range you want to send
        .Parent.Select

        'Remember the ActiveCell on that worksheet
        Set rng = ActiveCell

        'Select the range you want to mail
        .Select

        ' Create the mail and send it
        ActiveWorkbook.EnvelopeVisible = True
        With .Parent.MailEnvelope

            ' Set the optional introduction field thats adds
            ' some header text to the email body.
            .Introduction = "This is test mail 2."

            With .Item
                .To = "ron@debruin.nl"
                .CC = ""
                .BCC = ""
                .Subject = "My subject"
                .Send
            End With

        End With

        'select the original ActiveCell
        rng.Select
    End With

    'Activate the sheet that was active before you run the macro
    AWorksheet.Select

StopMacro:
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
    ActiveWorkbook.EnvelopeVisible = False

End Sub
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlanConsultantCommented:
Hi,

Inside your 'With .Item":

.Body = "Any text (optional)" & Activesheet.Range("A1") & " Yet more text (optional) " & Activesheet.Range("A2") & " Final text (optional) "

Should work.

It might depend on exactly what you have in the cells, and formatting might be interesting....

Alan.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rgonzo1971Commented:
Hi,

pls try ( by creating a temporary sheet with your data

Sub Send_Range_Or_Whole_Worksheet_with_MailEnvelope()
 'Working in Excel 2002-2013
     Dim AWorksheet As Worksheet
     Dim Sendrng As Range
     Dim rng As Range

   '  On Error GoTo StopMacro

     With Application
         .ScreenUpdating = False
         .EnableEvents = False
     End With

     'Fill in the Worksheet/range you want to mail
     'Note: if you use one cell it will send the whole worksheet
     Set AWorksheet = ActiveSheet
     Set tmpSh = Sheets.Add(after:=Worksheets(Worksheets.Count))
     Union(Worksheets("Sheet1").Range("C16:D17"), Worksheets("Sheet1").Range("C136:D165")).Copy tmpSh.Range("A1")
     
     Set Sendrng = tmpSh.UsedRange
     

     With Sendrng

         ' Select the worksheet with the range you want to send
         .Parent.Select

         'Remember the ActiveCell on that worksheet
         Set rng = ActiveCell

         'Select the range you want to mail
         .Select

         ' Create the mail and send it
         ActiveWorkbook.EnvelopeVisible = True
         With .Parent.MailEnvelope

             ' Set the optional introduction field thats adds
             ' some header text to the email body.
             .Introduction = "This is test mail 2."

             With .Item
                 .To = "raphael.gonzalez@credit-suisse.com"
                 .CC = ""
                 .BCC = ""
                 .Subject = "My subject"
                 .Send
             End With

         End With

         'select the original ActiveCell
         rng.Select
     End With
     Application.DisplayAlerts = False
     tmpSh.Delete
     Application.DisplayAlerts = True
     'Activate the sheet that was active before you run the macro
     AWorksheet.Select

StopMacro:
     With Application
         .ScreenUpdating = True
         .EnableEvents = True
     End With
     ActiveWorkbook.EnvelopeVisible = False

 End Sub

Open in new window

Regards
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.