rafaelbatalha
New Member
- Joined
- Jan 26, 2024
- Messages
- 3
- Office Version
- 2016
- Platform
- Windows
Hello and good day to all!
I have a problem that i can't solve.
I have a excel sheet that run's a macro every time a close it.
The macro creates an event in Outlook calenders of diferent recipients.
The problem is that every time i open the sheet and add a new event, the macro repeats the alreday created events when i just want it to add the newest event.
I am not a programer and don's know how to code.
I have this VBA code that i found online and it works for me but i don't know how to add the conditional format to make the macro run only on the most recent events.
can anyone please help??? here is the code
Option Explicit
Sub AddAppointments()
Dim myoutlook As Object ' Outlook.Application
Dim r As Long
Dim myapt As Object ' Outlook.AppointmentItem
Dim KeyCells As Range
Set KeyCells = Range("A2:J500")
If Not Application.Intersect(KeyCells, Range("A2:J500")) _
Is Nothing Then
End If
' late bound constants
Const olAppointmentItem = 1
Const olBusy = 2
Const olMeeting = 1
' Create the Outlook session
Set myoutlook = CreateObject("Outlook.Application")
' Start at row 2
r = 2
Do Until Trim$(Cells(r, 1).Value) = ""
' Create the AppointmentItem
Set myapt = myoutlook.CreateItem(olAppointmentItem)
' Set the appointment properties
With myapt
.Subject = Cells(r, 1).Value
.Location = Cells(r, 2).Value
.Start = Cells(r, 3).Value
.End = Cells(r, 4).Value
.Recipients.Add Cells(r, 8).Value
'.Recipients.Add Cells(r, 9).Value
'.Recipients.Add Cells(r, 10).Value
.MeetingStatus = olMeeting
' not necessary if recipients are email addresses
myapt.Recipients.ResolveAll
'.AllDayEvent = Cells(r, 9).Value
' If Busy Status is not specified, default to 2 (Busy)
If Len(Trim$(Cells(r, 5).Value)) = 0 Then
.BusyStatus = olBusy
Else
.BusyStatus = Cells(r, 5).Value
End If
If Cells(r, 6).Value > 0 Then
.ReminderSet = True
.ReminderMinutesBeforeStart = Cells(r, 6).Value
Else
.ReminderSet = False
End If
.Body = Cells(r, 7).Value
.Save
.send
r = r + 1
End With
Loop
End Sub
I have a problem that i can't solve.
I have a excel sheet that run's a macro every time a close it.
The macro creates an event in Outlook calenders of diferent recipients.
The problem is that every time i open the sheet and add a new event, the macro repeats the alreday created events when i just want it to add the newest event.
I am not a programer and don's know how to code.
I have this VBA code that i found online and it works for me but i don't know how to add the conditional format to make the macro run only on the most recent events.
can anyone please help??? here is the code
Option Explicit
Sub AddAppointments()
Dim myoutlook As Object ' Outlook.Application
Dim r As Long
Dim myapt As Object ' Outlook.AppointmentItem
Dim KeyCells As Range
Set KeyCells = Range("A2:J500")
If Not Application.Intersect(KeyCells, Range("A2:J500")) _
Is Nothing Then
End If
' late bound constants
Const olAppointmentItem = 1
Const olBusy = 2
Const olMeeting = 1
' Create the Outlook session
Set myoutlook = CreateObject("Outlook.Application")
' Start at row 2
r = 2
Do Until Trim$(Cells(r, 1).Value) = ""
' Create the AppointmentItem
Set myapt = myoutlook.CreateItem(olAppointmentItem)
' Set the appointment properties
With myapt
.Subject = Cells(r, 1).Value
.Location = Cells(r, 2).Value
.Start = Cells(r, 3).Value
.End = Cells(r, 4).Value
.Recipients.Add Cells(r, 8).Value
'.Recipients.Add Cells(r, 9).Value
'.Recipients.Add Cells(r, 10).Value
.MeetingStatus = olMeeting
' not necessary if recipients are email addresses
myapt.Recipients.ResolveAll
'.AllDayEvent = Cells(r, 9).Value
' If Busy Status is not specified, default to 2 (Busy)
If Len(Trim$(Cells(r, 5).Value)) = 0 Then
.BusyStatus = olBusy
Else
.BusyStatus = Cells(r, 5).Value
End If
If Cells(r, 6).Value > 0 Then
.ReminderSet = True
.ReminderMinutesBeforeStart = Cells(r, 6).Value
Else
.ReminderSet = False
End If
.Body = Cells(r, 7).Value
.Save
.send
r = r + 1
End With
Loop
End Sub