显示电子邮件正文vba的Range部分

时间:2018-05-29 11:27:36

标签: excel vba excel-vba email range

我想从我的工作表添加一个范围到生成的电子邮件的正文但是vba。我一直都会收到错误,感谢任何帮助

myRange = Range("A12:A12.End(xlDown)").SpecialCells(xlCellTypeVisible)

'This will extract the info for the worksheet
'This extracts the subject title from the worksheet

EmailSubject = "STOCKS " & Type1 & " - " & Left(Trade, 6) & " [" & _ 
               Range("A12").Value & "/" & Range("A12").End(xlDown).Value _
               & "]: % at %"

Body = "<b>" & Range("A8").Value & "</b><br/>" & Range("A9").Value & "<br/>" _ 
       & Range("A10").Value & "<br/><br/>" _
       & myRange

1 个答案:

答案 0 :(得分:3)

您的错误与您声明范围的方式有关。

  • 范围是一个对象,必须是Set
  • End(xlDown)无法作为字符串传递
  • 尝试定义范围的开始和结束单元格,然后正确定义范围:
Option Explicit

Sub TestMe()

    Dim myRange As Range
    Dim firstCell   As Range
    Dim lastCell As Range

    Set firstCell = Range("A12")
    Set lastCell = firstCell.End(xlDown)
    Set myRange = Range(firstCell, lastCell).SpecialCells(xlCellTypeVisible)

End Sub

一旦设法获得了正确的范围,就会更容易 - Paste specific excel range in outlook