我试图根据excel值自动发送电子邮件。这是我到目前为止的VBA。
Dim xRg As Range
Dim CurrentDate As Date
Dim MinDate As Date
Dim PrinterName As String
Dim ReamValue As Integer
Dim Record As Object
Private Sub Worksheet_Change(ByVal Target As Range)
CurrentDate = Date
MinDate = CurrentDate - 30
PrinterName = Range("E2")
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Range("F:F"), Target)
If xRg Is Nothing Then Exit Sub
For Each Record In Range(1, 7)
If IsNumeric(Target.Value) And Target.Value < 5 And DateDiff("w", CurrentDate, CurrentDate - 30) Then
Call Mail_small_Text_Outlook(CurrentDate, MinDate, PrinterName)
End If
End Sub
Sub Mail_small_Text_Outlook(CurrentDate As Date, MinDate As Date, PrinterName As String)
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi [Name]" & vbNewLine & vbNewLine & _
"Device at location [location name] is at quantity [quantityValue] and needs to be filled." & vbNewLine & _
"Thanks." & vbNewLine &
"Signature"
On Error Resume Next
With xOutMail
.To = "Enter_Email_Address_Here"
.CC = ""
.BCC = ""
.Subject = "Title"
.Body = xMailBody
.Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
我喜欢电子邮件,基本上将设备位置名称输入到电子邮件中,以及过去30天内所有设备与所述设备关联的数量。一旦发送电子邮件,所有记录都将从表格中删除。
Excel工作表中的列如下 StartTime / CompletionTime / Email / Name / What_Device_are_you /多少/ Additional_Comments
问题:如何访问电子邮件的Excel中的值。我不知道如何/似乎无法获得正确的格式。每行/记录都必须是它自己的对象吗?
先谢谢你的帮助: - )