hi all, i'm fairly new at VBA coding and has taking hours of searching goolge and these forums for help on each section of the code but............... i have the following code which, when outlook opens it automatically runs. It works ok if run manually once outlook has opened but if run automatically whilst outlook opens it comes across an error relating to the folderID (i presume these aren't assigned until outlook has fully opened)
the code, checks the current date is 7 days prior to a meeting date with the subject "TEST" and then sends an email out automatically giving a reminder and again 3 days prior with a different email.
The folder ID must be entered as it is looking in a folder which isn't my default mailbox calendar.
Set objoutlook = GetNamespace("MAPI")
Dim CalFolder As MAPIFolder
'This refers to the CEO Admin (UK) calendar ID:
Set CalFolder = Outlook.Session.GetFolderFromID("000000001ADF6F0FAD33164AA145CDD524E9CC7E01000D6A06F123737A43AAE999B0F1965903000001D8A13C0000")
Set CalItem = CalFolder.Items
For Each myitem In CalItem
'Subtracts the number of days that the original notice needs to be sent out
OrignalNotice = myitem.start(Date) - 7
'Subtracts the number of days that the Reminder notice needs to be sent out
ReminderNotice = myitem.start(Date) - 3
'Checks that the subject of the meeting matches what you require
'and checks that the current date is, that of the subtracted date above
If (myitem.Subject = "TEST") And (Format(OriginalNotice, "dd,mm,yyyy") = Format(Date, "dd,mm,yyyy")) Then
'creates the email that is to be sent in OrignalNotice
Set newitem = Application.CreateItem(0)
newitem.To = myitem.RequiredAttendees
newitem.CC = myitem.OptionalAttendees
newitem.Recipients.ResolveAll
newitem.Subject = myitem.Subject
newitem.Body = Format(myitem.start, "DD/MM/YYYY") & " " & myitem.Location
newitem.Display
End If
'Checks that the subject of the meeting matches what you require
'and checks that the current date is, that of the subtracted date above
If (myitem.Subject = "TEST") And (Format(ReminderNotice, "dd,mm,yyyy") = Format(Date, "dd,mm,yyyy")) Then
'creates the email that is to be sent in ReminderNotice
Set newitem = Application.CreateItem(0)
newitem.To = myitem.RequiredAttendees
newitem.CC = myitem.OptionalAttendees
newitem.Recipients.ResolveAll
newitem.Subject = "TRM TEST"
newitem.Body = "REMINDER OF PACK REQUIREMENTS!!" & myitem.start
newitem.Display
End If
Next
End Sub
Thanks for any help in advance!
Thanks again.
Bookmarks