首页 > 解决方案 > 在列中发送时如何取消vba的运行

问题描述

我有以下内容,如果“已发送”在 L 列中,我希望它不填充邀请。目的不是让一些邀请发送两次,如何实现?

Dim OutApp As Object
Dim OutMail As Object
Dim Cell As Range

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")

For Each Cell In Worksheets("Scheduler").Range("H2:H50").Cells
    Set OutMail = OutApp.CreateItem(1)

If Cell.Value Like "*@*" Then      'try with less conditions first
With OutMail
.MeetingStatus = olMeeting
.RequiredAttendees = Cells(Cell.Row, "H").Value
.Subject = Cells(Cell.Row, "I").Value
.Body = Cells(Cell.Row, "J").Value
.Start = Cells(Cell.Row, "E").Value
.Location = "Zoom Meeting"
.Duration = Cells(Cell.Row, "F").Value
.BusyStatus = 1.5 ' set as Busy
.ReminderSet = True 'reminder set
.ReminderMinutesBeforeStart = "15" 'reminder 2 weeks before
.Display
End With

Cells(Cell.Row, "L").Value = "sent"
Set OutMail = Nothing
End If
Next Cell

Application.ScreenUpdating = True

结束子

标签: vba

解决方案


一开始只是Cells(Cell.Row, "L").Value检查sent

For Each Cell In Worksheets("Scheduler").Range("H2:H50").Cells

    If Cells(Cell.Row, "L").Value <> "sent" then

        Set OutMail = OutApp.CreateItem(1)

        If Cell.Value Like "*@*" Then
        '... Rest of your code

    End if

next Cell

这样,仅处理 L 列中的值未“发送”的行。


推荐阅读