如何跳过VBA中的东西excel到outlook宏

时间:2014-01-23 12:04:59

标签: excel vba excel-vba outlook-vba

到目前为止,我已经开始使用宏来向我的excel列表中的每个人发送电子邮件,它工作正常,除了我需要添加更多的东西:

1,如果 Cells(r,4).Value 中的日期介于今天+7天和今天+14天之间,则仅向人们发送电子邮件,否则跳过该行。

2,如果已发送电子邮件,则将 Cells(r,20).Value 的值从“False”更改为“True”

3,跳过行是 Cells(r,20).Value 是“True”

到目前为止它是如何松动的:

  Sub SetupAppointmentList()
' adds a list of appontments to the Calendar in Outlook
Dim olApp As Outlook.Application
Dim olAppItem As Outlook.AppointmentItem
Dim r As Long
    DeleteNotices ' deletes previous test appointments
    On Error Resume Next
    Set olApp = GetObject("", "Outlook.Application")
    On Error GoTo 0
    If olApp Is Nothing Then
        On Error Resume Next
        Set olApp = CreateObject("Outlook.Application")
        On Error GoTo 0
        If olApp Is Nothing Then
            MsgBox "Outlook is not available!"
            Exit Sub
        End If
    End If




    r = 10 ' first row with data in
    While Len(Cells(r, 1).Formula) > 0
        Set olAppItem = olApp.CreateItem(olAppointmentItem)
        With olAppItem

            .MeetingStatus = olMeeting
            ' set default appointment values
            .Start = Now
            .End = Now
            .Subject = "No subject"
            .Location = ""
            .Body = ""
            .ReminderSet = True
            On Error Resume Next
            .Recipients.Add Cells(r, 3).Value
            .Recipients.ResolveAll
            .Start = Cells(r, 4).Value + Cells(r, 5).Value
            .End = Cells(r, 4).Value + Cells(r, 6).Value
            .Subject = "Interview"
            .Location = Cells(r, 13).Value + ", " + Cells(r, 14).Value
            .Body = "Hi.... Blah Blah Blah"
            .ReminderMinutesBeforeStart = 30
            .Categories = "Notice"            
     On Error GoTo 0
            .Save
            .Display
            '.Send


        End With
        r = r + 1
    Wend
    Set olAppItem = Nothing
    Set olApp = Nothing
End Sub

希望你能提供帮助,提前致谢!

1 个答案:

答案 0 :(得分:0)

不是在这里为你编写代码,而是在做什么:

获取Cells(r,4)的内容并使用CDate将其转换为日期。将它与您的开始和结束日期进行比较,如果它在范围内,则继续。

获取(r,20)的内容并使用CBool​​获取bool值。检查并确定是否继续。

发送电子邮件后,只需设置单元格(r,20)= true

试一试,看看它是怎么回事。