PhysiologyWeb Logo  Search
Share on Facebook Share on Twitter Share on LinkedIn Share on Pinterest Email Copy URL
PhysiologyWeb Loading...

Delphi Code - Create Microsoft Outlook Appointment Item
Here is a simple Delphi procedure that uses Microsoft Outlook to create a simple calendar appointment item programmatically. The code works well whether or not Outlook is already open. However, please note that the code will not work if Outlook is closed, and your installed Outlook requires any form of authentication upon launching the program. The most relevant parts of the code are highlighted. Comments are included to explain the code. If you copy and paste the code into your program, be sure to change the form and procedure names to match your setup. For additional Outlook automation solutions, see Microsoft Outlook Automation with Delphi.
procedure TForm1.UseDelphiToCreateMicrosoftOutlookAppointmentItem(Sender: TObject);
var
OutlookApplication, OutlookAppointmentItem: Variant;
begin
//be sure ComObj and Variants units are included in the "uses" clause

OutlookApplication := Null;
OutlookAppointmentItem := Null;

try
//create Outlook OLE
OutlookApplication := CreateOleObject('Outlook.Application');
except
OutlookApplication := Null;
//add error/exception handling code as desired
end;

If VarIsNull(OutlookApplication) = False then
begin
try
//Create Outlook Appointment Item
try
OutlookAppointmentItem := OutlookApplication.CreateItem(1); //olAppointmentItem = $00000001
//reference
//https://docs.microsoft.com/en-us/office/vba/api/outlook.appointmentitem
except
OutlookAppointmentItem := Null;
//add error/exception handling code as desired
end;

If VarIsNull(OutlookAppointmentItem) = False then
begin
OutlookAppointmentItem.Subject := 'Outlook Calendar Appointment';
OutlookAppointmentItem.Body := 'This Microsoft Outlook calendar appointment was created programmatically by Delphi!';
OutlookAppointmentItem.Location := 'My office';
OutlookAppointmentItem.AllDayEvent := False;
OutlookAppointmentItem.Start := EncodeDateTime(2022, 8, 7, 9, 0, 0, 0);
OutlookAppointmentItem.End := EncodeDateTime(2022, 8, 7, 9, 50, 0, 0);
OutlookAppointmentItem.Save;
//reference
//https://docs.microsoft.com/en-us/office/vba/api/outlook.appointmentitem
end;
finally
OutlookAppointmentItem := Unassigned;
OutlookApplication := Unassigned;
end;
end;
end;






Posted: Saturday, August 6, 2022
Last updated: Saturday, October 22, 2022