Outlook VBA .Restrict Uses Work Hours -
when use restrict set date range on outlook item object, not pick appointments before whatever have set "work hours" on outlook. how make whatever user sets "work hours" not influence macro?
eg. "work hours" in outlook set 1pm 5pm. create 4 appointments:
- 1111 @ 10am sept 4, 2017
- 2222 @ 1pm sept 4, 2017
- 3333 @ 6pm sept 4, 2017
- 4444 @ 1pm sept 5, 2017
my code pick last 3 appointments, not first, if dates enter 9/4/2017 , 9/5/2017.
sub restrictdemo() dim olkitems outlook.items, _ olkselected outlook.items, _ olkappt outlook.appointmentitem, _ datestart date, _ dateend date datestart = inputbox("starting date?", "", "m/d/yyyy") dateend = inputbox("ending date?", "", "m/d/yyyy") if isdate(datestart) , isdate(dateend) set olkitems = session.getdefaultfolder(olfoldercalendar).items olkitems.includerecurrences = true olkitems.sort "start" set olkselected = olkitems.restrict("[start] >= '" & datestart & "' , [start] <= '" & dateend & "'") each olkappt in olkselected counter = counter + 1 msgbox counter msgbox olkappt.subject & " " & olkappt.location & olkappt.start next else msgbox "you must enter valid starting , ending dates run macro.", vbcritical + vbokonly, macro_name end if end sub
use format expected restict. https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/items-restrict-method-outlook
sub restrictdemo() dim counter long dim olkitems items dim olkselected items dim olkappt appointmentitem dim datestart dim dateend dim strfilter string ' may need use different date format. datestart = inputbox("starting date?", , "2017-08-22") dateend = inputbox("ending date?", , "2017-08-23") if isdate(datestart) , isdate(dateend) set olkitems = session.getdefaultfolder(olfoldercalendar).items olkitems.includerecurrences = true olkitems.sort "start" 'strfilter = "[start] >= '" & datestart & "' , [start] < '" & dateend & "'" 'debug.print strfilter strfilter = "[start] >= '" & format(datestart, "ddddd h:nn ampm") & "'" debug.print strfilter strfilter = strfilter & " , [start] < '" & format(dateend, "ddddd h:nn ampm") & "'" debug.print strfilter set olkselected = olkitems.restrict(strfilter) each olkappt in olkselected counter = counter + 1 debug.print counter & ":" & olkappt.subject & " " & olkappt.location & olkappt.start 'msgbox counter & ":" & olkappt.subject & " " & olkappt.location & olkappt.start next else msgbox "enter valid starting , ending dates.", vbcritical + vbokonly, "macro_name" end if end sub the deeper question of why day begins @ start of work day , continues 24 hours remains unanswered.
Comments
Post a Comment