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
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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.
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top