Stop duplicating entries when using a Macro to post dates from Excel into Outlook

as1234

New Member
Joined
Oct 4, 2015
Messages
3
Hi,

I am using the following macro to post dates from excel into outlook, however, each time I run the macro it duplicates the entry in Outlook. Any help on how to stop this would be greatly appreciated:


Sub AddAppointments()
' Create the Outlook session
Set myOutlook = CreateObject("Outlook.Application")


' Start at row 5
r = 5


Do Until Trim(Cells(r, 1).Value) = ""
' Create the AppointmentItem
Set myApt = myOutlook.createitem(1)
' Set the appointment properties
myApt.Subject = Cells(r, 6).Value & " Reset"
myApt.Location = Cells(r, 1).Value
myApt.Start = Cells(r, 33).Value
myApt.Duration = 0
myApt.BusyStatus = 0
myApt.ReminderSet = True
myApt.ReminderMinutesBeforeStart = 720
myApt.Save
r = r + 1
Loop


End Sub
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,467
Hi As1234 -- Welcome to Mr Excel.

Your Macro Sub AddAppointments(), like any Macro of this nature does not have a memory. That is why it is repeating your date.
For me the classic work-around so you can achieve your goal is to each time you run the macro to keep a record of the date(s) previously passed to your Outlook App.

Within your loop test your date to see if it has already been passed to Outlook (the date is in your Log of dates previously passed to Outlook). If the date is not in the Log, then add it to the log for the
next time you run the macro.
 

as1234

New Member
Joined
Oct 4, 2015
Messages
3
Thanks Jim. How would you alter the macro if several people need to run the macro to update their outlook calendar? Could you show how you would alter the above code?
 

Watch MrExcel Video

Forum statistics

Threads
1,095,246
Messages
5,443,321
Members
405,227
Latest member
Ankit Jain

This Week's Hot Topics

Top