我正在尝试将一系列特定单元格插入到我的电子邮件正文中
我能够指定我想要的单元格的范围,但是,我再次收到不匹配错误。
我以前对我的收件人变量也有一个相当相似的问题,并且已经解决了,这要感谢 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
如果可能的话,我也想知道为什么。