Put text body above the pasted range

0 votes

I have a code that pastes a range into an email body, but the text body is where I'm having trouble. When the code runs, the body is below the supplied range; perhaps someone can offer advice on how to make it higher?

Sub SendEmailWithRange()
    Dim MyRange As Range
    Dim doc As Object
    
    Set MyRange = Sheets("Sheet1").Range("A4").CurrentRegion
    
    With CreateObject("outlook.application").CreateItem(0)
        .Display 'Change to .Send to send the email immediately
        .Body = "This is the body:" '& vbNewLine & vbNewLine
            Set doc = .GetInspector.WordEditor
            MyRange.Copy
            doc.Range(x, x).Paste
        .To = Range("I3").Value
        .Subject = "My subject"
        Application.CutCopyMode = 0
    End With
    
End Sub
Feb 20, 2023 in Others by narikkadan
• 63,420 points
222 views

1 answer to this question.

0 votes

Set x before you paste. x = doc.Range.End - 1 finds the end of the document less 1

    Sub SendEmailWithRange()
    Dim MyRange As Range
    Dim doc As Object
    
    Set MyRange = Sheets("Sheet1").Range("A4").CurrentRegion
    
    With CreateObject("outlook.application").CreateItem(0)
        .Display                                 'Change to .Send to send the email immediately
        
        .Body = "This is the body:"              '& vbNewLine & vbNewLine
        Set doc = .GetInspector.WordEditor
        
        x = doc.Range.End - 1
        MyRange.Copy
        doc.Range(x).Paste
            
        .To = Range("I3").Value
        .Subject = "My subject"
        
        Application.CutCopyMode = 0
    End With
    
End Sub
answered Feb 20, 2023 by Kithuzzz
• 38,010 points

Related Questions In Others

0 votes
1 answer

How to retrieve the value of a text field in Flutter App?

Hi@akhtar, In your TextField, you can call one ...READ MORE

answered Sep 3, 2020 in Others by MD
• 95,440 points
1,527 views
0 votes
1 answer

What are the important meta tags I must put in my website? [closed]

Regular meta info <title>{{pageTitle}}</title> <meta charset="utf-8"><!-- html5 version ...READ MORE

answered Feb 11, 2022 in Others by narikkadan
• 63,420 points
308 views
0 votes
1 answer

What is the difference between POST and PUT in HTTP?

To answer your question, both of them ...READ MORE

answered Feb 11, 2022 in Others by Rahul
• 9,670 points
422 views
0 votes
1 answer
0 votes
1 answer

Embed picture in outlook mail body excel vba

The image needs to be added and ...READ MORE

answered Dec 16, 2022 in Others by narikkadan
• 63,420 points
4,548 views
0 votes
1 answer

VBA How to extract the date and time of arrival of a answered email

Use MailItem.ReceivedTime property. I hope this helps you ...READ MORE

answered Jan 9, 2023 in Others by narikkadan
• 63,420 points
2,172 views
0 votes
1 answer

Error populating email body from word documents

There is no need to use late ...READ MORE

answered Jan 15, 2023 in Others by narikkadan
• 63,420 points
954 views
0 votes
1 answer

Export All appointments and meetings (including recurring meetings) Excel VBA

However, when I use the code above ...READ MORE

answered Feb 13, 2023 in Others by narikkadan
• 63,420 points
1,190 views
0 votes
1 answer
0 votes
1 answer

Excel Script keeps giving error "Range merge: You cannot perform the requested operation."

Range.merge() Operation is not possible in ExcelScript ...READ MORE

answered Feb 23, 2023 in Others by Kithuzzz
• 38,010 points
757 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP