WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE and Outlook
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get list of appointments

Keywords:   Outlook calendar

Question:

I need to create a script to write a file from several calender boxes. The result should be a list with all the appointments.

Answer:

Hope this helps get you started

;---------------------------------------------------------------------------
; Outlook_Calendar
;---------------------------------------------------------------------------

;These variables help define a date search filter
StartDateUS = "5/23/1997"
EndDateUS = "5/23/2002"

olPrivate        = 2
olFolderCalendar = 9

objOutlook   = ObjectOpen("Outlook.Application")
objMAPI      = objOutlook.GetNameSpace("MAPI")
objCalendar = objMAPI.GetDefaultFolder(olFolderCalendar)
objItems    = objCalendar.Items

objCurrent   = objMAPI.CurrentUser
objName      = objCurrent.Name
;objName      = "Joe Shmoe"

restriction = StrCat('[Start] >= "',StartDateUS,'" And [End] <= "',EndDateUS,'"')
objRestrict = objItems.Restrict(restriction)
objRestrict.Sort("[Start]")
objFirst    = objRestrict.GetFirst

;check if there are any appointments
if objFirst != 0
	ApptSubject = objFirst.Subject
	ApptStart   = objFirst.Start
	ApptEnd     = objFirst.End
	ApptStatus  = objFirst.BusyStatus
	ApptADE     = objFirst.AllDayEvent
	
	if ApptADE == -1 then
	        ADEflag = "All Day Event"
	else
	        ADEflag = ""
	end if
	if objFirst.Sensitivity == olPrivate then ApptSubject = "PRIVATE"
	BusyStatus = ""
	switch ApptStatus
	        case 1
	                BusyStatus = "Tentative  %ADEflag%"
	                break
	        case 2
	                BusyStatus = "Busy  %ADEflag%"
	                break
	        case 3
	                BusyStatus = "Out of Office  %ADEflag%"
	                break
	end switch
	
	output = FileOpen("c:\temp\outlook.txt","WRITE")
	FileWrite(output,"4 week calendar")
	FileWrite(output,StrCat(ApptStart,@tab,ApptEnd,@tab,ApptSubject,@tab,BusyStatus))
	
	for i = 2 to objRestrict.Count
	        objFirst    = objRestrict.GetNext
	        ApptSubject = objFirst.Subject
	        ApptStart   = objFirst.Start
	        ApptEnd     = objFirst.End
	        ApptStatus  = objFirst.BusyStatus
	        ApptADE     = objFirst.AllDayEvent
	
	        if ApptADE == -1 then
	                ADEflag = "All Day Event"
	        else
	                ADEflag = ""
	        end if
	        if objFirst.Sensitivity == olPrivate then ApptSubject = "PRIVATE"
	
	
	        switch ApptStatus
	                case 1
	                        BusyStatus = "Tentative  %ADEflag%"
	                        break
	                case 2
	                        BusyStatus = "Busy  %ADEflag%"
	                        break
	                case 3
	                        BusyStatus = "Out of Office  %ADEflag%"
	                        break
	        end switch
	
	        FileWrite(output,"%ApptStart%  %ApptEnd%  %ApptSubject%  %BusyStatus%")
	next i
Else
  Message("Appointment checker","No Appointments found")
Endif

ObjectClose(objOutlook)
FileClose(output)




Article ID:   W14682
Filename:   Get list of appointments.txt
File Created: 2003:09:10:07:31:48
Last Updated: 2003:09:10:07:31:48