How to transfer a specific column range (with value/text) using Excel VBA to body of Outlook in plain text.
I got the code for TO and Subject line, the problem is the body text.
Most of the solutions via internet is to transfer a table, pasted as image.
How to transfer a specific column range (with value/text) using Excel VBA to body of Outlook in plain text.
I got the code for TO and Subject line, the problem is the body text.
Most of the solutions via internet is to transfer a table, pasted as image.
Share Improve this question edited Apr 8 at 13:59 CommunityBot 11 silver badge asked Jan 19 at 7:28 g00reg00re 256 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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745343264a4623427.html
.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