简体   繁体   English

复制某个单元格范围并粘贴到Outlook邮件正文中

[英]Copying a certain cell range and pasting in outlook mail body

My Questions: 我的问题:

Is there any way to copy a cell range and paste it in the outlook mail body programatically? 是否可以通过编程方式复制单元格范围并将其粘贴到Outlook邮件正文中?

I have this code, but it doesn't seem to copy the cell range, but if you type in an individual cell (ex. A4), it's able to copy it. 我有这段代码,但似乎没有复制单元格范围,但是如果您键入单个单元格(例如A4),则可以复制它。

Sub Email()
   Dim xOutApp As Object
   Dim xOutMail As Object
   Dim xMailBody As String
   Dim szTodayDate As String
   szTodayDate = Format(Date, "mm.dd.yyyy")
   On Error Resume Next
   Set xOutApp = CreateObject("Outlook.Application")
   Set xOutMail = xOutApp.CreateItem(0)
   xMailBody = ActiveSheet.Range("A4:B4").Value
              On Error Resume Next
  With xOutMail
    .To = "tryemail@gmail.com"
    .CC = "tryemail2@gmail.com"
    .BCC = ""
    .Subject = "Schedule for deal pursuit" & " " & szTodayDate
    .Body = xMailBody
    .Display   'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub

That's the only idea I had .. using a loop to add every cell value to the bodyMail .. 那是我唯一的想法..使用循环将每个单元格值添加到bodyMail ..

         xMailBody = ""
        ' i represents the columns
        For i = 1 To 2
             xMailBody = xMailBody & " " & ActiveSheet.Cells(4, i).Value
        Next i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM