最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

vba - VB Script Excel - column range to outlook - Stack Overflow

programmeradmin4浏览0评论

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
  • Are you looking for a code to do that? Why not right click > Paste > Keep text only ? – Ali Sheikhpour Commented Jan 19 at 7:44
  • i know what you mean.... yes im looking for a code.... we will use it for our work related. – g00re Commented Jan 19 at 8:03
  • 1 @g00re This article will show you the method. jkp-ads.com/rdb/win/s1/outlook/bmail2.htm – Harun24hr Commented Jan 19 at 8:09
  • 2 Try .Body = VBA.Join(Application.Transpose(rng), vbLf) where rng 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
Add a comment  | 

1 Answer 1

Reset to default 1

This 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
发布评论

评论列表(0)

  1. 暂无评论