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 in Others by narikkadan
• 59,740 points
67 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 by Kithuzzz
• 34,760 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,460 points
1,176 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
• 59,740 points
135 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
183 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
• 59,740 points
1,031 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 in Others by narikkadan
• 59,740 points
332 views
0 votes
1 answer

Error populating email body from word documents

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

answered Jan 15 in Others by narikkadan
• 59,740 points
86 views
0 votes
1 answer
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 in Others by Kithuzzz
• 34,760 points
104 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