-1

我正在尝试将一系列特定单元格插入到我的电子邮件正文中

我能够指定我想要的单元格的范围,但是,我再次收到不匹配错误。

我以前对我的收件人变量也有一个相当相似的问题,并且已经解决了,这要感谢 David Zemens

PS:我真的对Outlook上的这种电子邮件自动化了解不多

我会很感激你的帮助。我的代码如下

Dim A As New Outlook.Application
Dim B As MailItem
Dim expireditems As Range
Dim addresses As String
Dim addressesrange As Range
Dim msg As String

Set expireditems = Nothing

Set A = New Outlook.Application
Set B = A.CreateItem(olMailItem)

LastR5 = ThisWorkbook.Sheets("Expired").Cells(Rows.Count, 1).End(xlUp).Row
LastR6 = ThisWorkbook.Sheets("Expired").Cells(Rows.Count, 7).End(xlUp).Row

For Each addressesrange In ThisWorkbook.Sheets("Expired").Range("G3:G" & LastR6).Cells
 addresses = addresses & ";" & addressesrange.Value
Next

Set expireditems = ThisWorkbook.Sheets("Expired").Range("A2:E" & LastR5).SpecialCells(xlCellTypeVisible)

If expireditems Is Nothing Then
        MsgBox "There are no expired items today"
        Exit Sub
    End If

msg = "Please remove the listed expired items." & vbCr & expireditems
'MISMATCH HERE AGAIN


With B
    .To = addresses
    .Subject = "Attention: Expired Items"
    .Body = msg
    .Importance = olImportanceHigh 'High importance
    .Display
End With

如果可能的话,我也想知道为什么。

4

1 回答 1

2

我能够指定我想要的单元格的范围,但是,我再次收到不匹配错误。

msg = "请删除列出的过期项目。" & vbCr & 过期物品

'这里又不匹配了

expireditems被定义为一个范围。你不能在这样的字符串中使用它。

换行

msg = "Please remove the listed expired items." & vbCr & expireditems

msg = "Please remove the listed expired items." & vbCr & expireditems.Address

此外,如果您想将范围导入电子邮件正文,那么您可能还想查看 Ron 关于RangetoHTML的文章

于 2013-11-14T07:18:28.707 回答