I have some code working to import data from Excel when a cell contains the word "Yes". I would like to include code to ignore any entries that have previously been imported when I run the code again.
Sub Permits()
Dim OL As Outlook.Application, Appoint As Outlook.AppointmentItem, ES As Worksheet, _
r As Long, i As Long, WB As ThisWorkbook
Set WB = ThisWorkbook
Set ES = WB.Sheets("Permits")
r = ES.Cells(Rows.Count, 1).End(xlUp).Row
Set OL = New Outlook.Application
For i = 2 To r
If ES.Cells(i, 10) = "Yes" Then
Set Appoint = OL.CreateItem(olAppointmentItem)
With Appoint
.Subject = ES.Cells(i, 3).Value
.Start = ES.Cells(i, 7) + ES.Cells(i, 8).Value
.ReminderSet = True
.ReminderMinutesBeforeStart = 60
.Body = "£" & ES.Cells(i, 6).Value
.Save
End With
End If
Next i
Set OL = Nothing
End Sub
You can mark processed rows with a green colour for example: (edited as req, it looks for "Yes" in cell 11)
Option Explicit
Option Compare Text 'ignore case sensitivity when comparing strings
Sub Permits()
Dim OL As Outlook.Application, ES As Worksheet, _
r As Long, i As Long, WB As ThisWorkbook
Set WB = ThisWorkbook
Set ES = WB.Sheets("Permits")
Set OL = New Outlook.Application
r = ES.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To r
With ES.Cells(i, 10)
If .Value = "Yes" And .Offset(0, 1).Value <> "Yes" Then
.Offset(0, 1).Value = "Yes"
With OL.CreateItem(olAppointmentItem)
.Subject = ES.Cells(i, 3).Value
.Start = ES.Cells(i, 7) + ES.Cells(i, 8).Value
.ReminderSet = True
.ReminderMinutesBeforeStart = 60
.Body = "£" & ES.Cells(i, 6).Value
.Save
End With
End If
End With
Next i
Set OL = Nothing
Set WB = Nothing
Set ES = Nothing
End Sub
You could also create a separate column to mark them etc, edit as needed. Alternatively, you can keep the spreadsheet 'clean' and search for existing reminders with the same data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.