发送一个包含所有单元格数值的电子邮件。

huangapple go评论148阅读模式
英文:

Send one email with all cell values

问题

在我的Excel表格中,如果符合我的条件,我有一列将填充单元格值。
我的代码遍历该列的每一行,如果一个单元格有值,它将自动发送一封电子邮件。

我希望代码能找出所有不为空的行,并只发送一封电子邮件,电子邮件的主题或正文显示从第一个到最后一个单元格的值。我希望主题行为从第一个单元格的值到最后一个单元格的值。

Sub Email()

    Dim OL As Outlook.Application, Appoint As Outlook.AppointmentItem, ES As Worksheet, _
    r As Long, i As Long, WB As ThisWorkbook, j As Long, k As Long

    Set WB = ThisWorkbook
    Set ES = WB.Sheets("Automatic Email Reminder")
    r = ES.Cells(Rows.Count, 1).End(xlUp).Row
    k = ES.Cells(Rows.Count, 1).End(xlUp).Row
    Set OL = New Outlook.Application

    For i = 4 To r
        If ES.Cells(i, 6) = "" Then 'change this (5 for M&C, 6 for CP, 7 for Objection)

        Else
            Set Appoint = OL.CreateItem(olAppointmentItem)
            With Appoint
                .Subject = ES.Cells(i, 6).Value  
                .RequiredAttendees = "example@email.com"
                .Start = ES.Cells(i, 8).Value
                .Duration = 5
                .ReminderMinutesBeforeStart = 2880
                .Body = ES.Cells(i, 6).Value 
                .MeetingStatus = olMeeting
                .Send
            End With
        End If
    Next i
    Set OL = Nothing

End Sub
英文:

In my Excel table, I have a column that will populate cell values if it meets my criteria.
My code goes through each of the rows in that column, and if a cell has a value it will populate a single email for each row to send automatically.

I would like the code to figure out all the rows that are not blank, and send only one email with the subject or body of the email showing the cell's value from first to last. I would like the subject line to be first cell value to last cell value.

Sub Email()

    Dim OL As Outlook.Application, Appoint As Outlook.AppointmentItem, ES As Worksheet, _
    r As Long, i As Long, WB As ThisWorkbook, j As Long, k As Long

    Set WB = ThisWorkbook
    Set ES = WB.Sheets("Automatic Email Reminder")
    r = ES.Cells(Rows.Count, 1).End(xlUp).Row
    k = ES.Cells(Rows.Count, 1).End(xlUp).Row
    Set OL = New Outlook.Application

    For i = 4 To r
        If ES.Cells(i, 6) = "" Then 'change this (5 for M&C, 6 for CP, 7 for Objection)

        Else
            Set Appoint = OL.CreateItem(olAppointmentItem)
            With Appoint
                .Subject = ES.Cells(i, 6).Value  
                .RequiredAttendees = "example@email.com"
                .Start = ES.Cells(i, 8).Value
                .Duration = 5
                .ReminderMinutesBeforeStart = 2880
                .Body = ES.Cells(i, 6).Value 
                .MeetingStatus = olMeeting
                .Send
            End With
        End If
    Next i
    Set OL = Nothing

End Sub

答案1

得分: 0

你需要在循环中创建一个预约主体字符串,之后可以发送一个会议邀请,例如:

Dim apptBody as String 
For i = 4 To r
    apptBody = apptBody & ES.Cells(i, 6).Value
Next i

Set Appoint = OL.CreateItem(olAppointmentItem)
With Appoint
 .Subject = ES.Cells(i, 6).Value  
 .RequiredAttendees = "example@email.com"
 .Start = ES.Cells(i, 8).Value
 .Duration = 5
 .ReminderMinutesBeforeStart = 2880
 .Body = apptBody 
 .MeetingStatus = olMeeting
 .Send
End With
英文:

You need to create an appointment body string in the loop after which you could send a meeting request, for example:

Dim apptBody as String 
For i = 4 To r
    apptBody = apptBody & ES.Cells(i, 6).Value
Next i

Set Appoint = OL.CreateItem(olAppointmentItem)
With Appoint
 .Subject = ES.Cells(i, 6).Value  
 .RequiredAttendees = "example@email.com"
 .Start = ES.Cells(i, 8).Value
 .Duration = 5
 .ReminderMinutesBeforeStart = 2880
 .Body = apptBody 
 .MeetingStatus = olMeeting
 .Send
End With

huangapple
  • 本文由 发表于 2023年3月10日 01:53:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75688339.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定