how to transfer a specific column range(with value/text) using excel to body of outlook in plain text. i cant figure it out and cant find a solution. I got the code for TO and Subject line the problem is the body text. most of the solution via internet is to transfer a table, past as image.
Thanks in advance.
how to transfer a specific column range(with value/text) using excel to body of outlook in plain text. i cant figure it out and cant find a solution. I got the code for TO and Subject line the problem is the body text. most of the solution via internet is to transfer a table, past as image.
Thanks in advance.
Share Improve this question asked Jan 19 at 7:28 g00reg00re 255 bronze badges 4 |1 Answer
Reset to default 1This is a code for adding into the email body the defined range of the ActiveSheet as text.
Sub tomail()
Dim srcrng As Range
Set srcrng = Range("A2:B10") 'the range to insert as text
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
RowDelim = Chr(10) 'to separate rows
ColDelim = "," 'to separate columns
For i = 1 To srcrng.Rows.count
For j = 1 To srcrng.Columns.count
If Len(stringto) = 0 Then
stringto = srcrng(i, j)
ElseIf j = 1 Then
stringto = stringto & srcrng(i, j)
Else
stringto = stringto & ColDelim & srcrng(i, j)
End If
Next j
stringto = stringto & RowDelim
Next i
olMail.BodyFormat = 1
olMail.body = olMail.body & stringto
olMail.display
olMail.Close olDiscard
End Sub
.Body = VBA.Join(Application.Transpose(rng), vbLf)
whererng
is a reference to the single-column range (e.g.Dim rng As Range: Set rng = Sheet1.Range("B6:B17")
). – VBasic2008 Commented Jan 19 at 8:27