Trying to enter 3 lines in a body of an email before I paste an image

JiggersBass

New Member
Joined
May 20, 2022
Messages
13
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Sub Email()
'Copy range of interest
Dim r As Range
Set r = Range("a1:g20")
r.Copy

'Open a new mail item
Set outlookApp = CreateObject("Outlook.Application")
Set outMail = outlookApp.CreateItem(olMailItem)
strbody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"

With outMail
.to = Range("a22")
.cc = Range("a23")
.Subject = Range("a24")
End With

'Get its Word editor
outMail.Display
Set wordDoc = outMail.GetInspector.WordEditor
wordDoc.Range.PasteAndFormat wdChartPicture

'To paste as a table
'wordDoc.Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False

End Sub
 

Attachments

  • Possible Output.png
    Possible Output.png
    8.2 KB · Views: 9
  • Actual Output.png
    Actual Output.png
    14.5 KB · Views: 9

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try the following code. You'll notice that I have used late binding for both libraries, Outlook and Word, for consistency.

VBA Code:
Sub Email()

    'Copy range of interest
    Dim r As Range
    Set r = Range("a1:g20")
    r.Copy
    
    'Create an instance of Outlook
    Dim outlookApp As Object
    Set outlookApp = CreateObject("Outlook.Application")
    
    'Create an email
    Dim outMail As Object
    Set outMail = outlookApp.CreateItem(0) 'olMailItem
    
    Dim strBody As String
    strBody = "Hi there" & vbNewLine & vbNewLine & _
    "This is line 1" & vbNewLine & _
    "This is line 2" & vbNewLine & _
    "This is line 3" & vbNewLine & _
    "This is line 4"
    
    With outMail
        .display
        .to = Range("a22").Value
        .cc = Range("a23").Value
        .Subject = Range("a24").Value
        .body = strBody
        Dim wordDoc As Object
        Set wordDoc = .GetInspector.WordEditor
    End With
    
    With wordDoc
        .Application.Selection.EndKey Unit:=6 'wdStory
        .Application.Selection.TypeParagraph
        .Application.Selection.TypeParagraph
        .Application.Selection.PasteAndFormat 13 'wdChartPicture
    End With

End Sub

Hope this helps!
 
Upvote 0
Is there a way that we can indent pasted image and call the signature as well?
 

Attachments

  • ActualOutput.png
    ActualOutput.png
    55.1 KB · Views: 7
  • Desired Output.png
    Desired Output.png
    54.5 KB · Views: 9
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,198
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top