【问题标题】:Display a Range part of the email body vba显示电子邮件正文 vba 的范围部分
【发布时间】:2018-05-29 11:27:36
【问题描述】:

我想将我的工作表中的范围添加到生成但 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

【问题讨论】:

  • 代码 sn-p 甚至无法编译,特别是 EmailSubject... 部分。您需要在行尾添加一个“_”。
  • 全部在一行中,只是这里的编辑器把它剪掉了
  • 听起来很奇怪,但你真的应该编辑你的帖子。一般来说,发布甚至无法编译的代码是一个很大的禁忌。

标签: vba excel email range


【解决方案1】:

您的错误在于您声明范围的方式。

  • 范围是一个对象,它必须是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

【讨论】:

  • @theudster - 只需从here 中获取答案,并在我的答案中声明您的范围。它应该可以工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-18
  • 1970-01-01
  • 2022-08-03
  • 2020-11-09
  • 1970-01-01
  • 2019-05-02
  • 1970-01-01
相关资源
最近更新 更多