Ok guys, I'm reaching again...
I have a spreadsheet that I need to initiate an outlook calendar event/ reminder for 25 days after the date entered. Through much research and trial & error, I have a VBA code written that almost does what I need. I just need some assistance in tweaking it a bit. This code does add entries to my calendar as written but not all of what I need (see below). Thanks in advance for any light you can shed.
What I need:
1. After I enter data into a row to include a date in column B, I need the code to run. This is probably best if I run upon saving or closing the workbook so I don't accidentally send the calendar event without entering all of the data for the day. Right now the code only runs when I manually initiate it.
2. I need the code to add events only for new data entered each time I save/close. I do not need repeat entries each time I save.
3. I would love for the entries to go into a specific calendar (Labeled "Personal") other than my default, but I can tackle that another time.
Here's my current code:
Also, right now, when I run the code, I only get entries from the data in rows 6 and 7. I tried to add these lines to the code but I ended up with a loop that wouldn't stop adding the first entry continuously. I literally deleted over 200 calendar entries of just Row 6.
I also tried This but nothing at all happened:
I have a spreadsheet that I need to initiate an outlook calendar event/ reminder for 25 days after the date entered. Through much research and trial & error, I have a VBA code written that almost does what I need. I just need some assistance in tweaking it a bit. This code does add entries to my calendar as written but not all of what I need (see below). Thanks in advance for any light you can shed.
What I need:
1. After I enter data into a row to include a date in column B, I need the code to run. This is probably best if I run upon saving or closing the workbook so I don't accidentally send the calendar event without entering all of the data for the day. Right now the code only runs when I manually initiate it.
2. I need the code to add events only for new data entered each time I save/close. I do not need repeat entries each time I save.
3. I would love for the entries to go into a specific calendar (Labeled "Personal") other than my default, but I can tackle that another time.
Here's my current code:
Code:
Option Explicit
Private Sub CreateAppointment()
' adds a list of appontments to the Calendar in Outlook
Dim olApp As Outlook.Application
Dim olAppItem As Outlook.AppointmentItem
Dim r As Long
On Error Resume Next
Worksheets("17-18 MMRRF").Activate
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 = 6 ' first row with appointment data in the active worksheet
Dim mysub, myStart, myEnd
While Len(Cells(r, 2).Text) <> 0
mysub = "MMRRF" & Cells(r, 3) & "Response Due"
myStart = DateValue(Cells(r, 2).Value + 25)
myEnd = DateValue(Cells(r, 2).Value + 25)
'DeleteTestAppointments mysub, myStart, myEnd
Set olAppItem = olApp.CreateItem(olAppointmentItem) ' creates a new appointment
With olAppItem
' set default appointment values
.Location = "MMRRF"
.Body = "Response Due in 5 days"
.ReminderSet = True
.BusyStatus = olFree
'.RequiredAttendees = "Myname@mailserver.com"
On Error Resume Next
.Start = myStart
.End = myEnd
.Subject = "MM Response due in 5 Days" & " - " & Cells(r, 3)
.Location = "MMRRF"
.Body = .Subject
.ReminderSet = True
.BusyStatus = olBusy
.Categories = "Important Event"
On Error GoTo 0
.Save ' saves the new appointment to the default folder
End With
r = r + 1
Wend
Set olAppItem = Nothing
Set olApp = Nothing
End Sub
Also, right now, when I run the code, I only get entries from the data in rows 6 and 7. I tried to add these lines to the code but I ended up with a loop that wouldn't stop adding the first entry continuously. I literally deleted over 200 calendar entries of just Row 6.
Code:
Private Sub CreateAppointment()
' adds a list of appontments to the Calendar in Outlook
Dim olApp As Outlook.Application
Dim olAppItem As Outlook.AppointmentItem
Dim r As Long
'.....
End If
End If
[COLOR=#ff0000] For r = 6 To 300 [/COLOR]'(I don't have 300 rows but wanted to cover it just in case. Would rather do auto count to last row but couldn't get that to work either.)
Dim mysub, myStart, myEnd
While Len(Cells(r, 2).Text) <> 0
'.....
End With
Wend
[COLOR=#ff0000] Next r[/COLOR]
Set olAppItem = Nothing
Set olApp = Nothing
End Sub
I also tried This but nothing at all happened:
Code:
Private Sub CreateAppointment()
' adds a list of appontments to the Calendar in Outlook
Dim olApp As Outlook.Application
Dim olAppItem As Outlook.AppointmentItem
Dim r As Long
[COLOR=#ff0000] Dim lr As Long[/COLOR]
'.....
End If
End If
[COLOR=#ff0000] lr = Cells(Rows.Count, 2).End(xlUp).Row[/COLOR]
[COLOR=#ff0000] For r = 6 To lr [/COLOR]'(I don't have 300 rows but wanted to cover it just in case. Would rather do auto count to last row but couldn't get that to work either.)
Dim mysub, myStart, myEnd
While Len(Cells(r, 2).Text) <> 0
'.....
End With
Wend
[COLOR=#ff0000] Next r[/COLOR]
Set olAppItem = Nothing
Set olApp = Nothing
End Sub