将特定范围放入电子邮件正文中的不匹配

时间:2013-11-14 07:15:18

标签: excel vba excel-vba outlook range

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

我可以指定我想要的单元格范围,但是,我再次遇到不匹配错误。

我以前对我的收件人变量也有类似的问题,并且由于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

如果可能,我也想知道原因。

1 个答案:

答案 0 :(得分:2)

  

我可以指定我想要的单元格范围,但是,我再次遇到不匹配错误。

     

msg ="请删除列出的过期项目。" &安培; vbCr& expireditems

     

' MISMATCH HERE AGAIN

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

更改行

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

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

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

的文章