2014-01-23 30 views
-1

到目前为止,我有工作在宏发电子邮件给每个人都在我的Excel列表,它工作正常,除了我需要一对夫妇更多的东西添加到它:如何跳过的东西在VBA擅长于预期宏观

1,仅在单元(r,4)。值中的日期在今天+7天和今天+14天之间发送电子邮件给人,否则跳过该行。

2,细胞(R,20)。价值从 “假” 为 “True”

3,跳过行如果电子邮件已发送变化值分别为细胞(R,20)。价值是“真”

其继承人如何洛斯至今:

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 

希望你能帮助,在此先感谢!

回答

0

而不是编写代码,你在这里就是你要做的:

获取细胞的含量(R,4),并使用CDate将其转换为一个日期。将它与您的开始和结束日期进行比较,如果它在范围内,请继续。

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

发送电子邮件,只需设置细胞后(R,20)=真

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

+0

谢谢,即时通讯仍然很新vba的东西。我没有明确地确定我的代码中如何或在哪里,我需要把这个。 – Rardo