ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Create Appointment in Outlook (https://www.excelbanter.com/excel-programming/425132-create-appointment-outlook.html)

[email protected]

Create Appointment in Outlook
 
I'm trying to use the following code in Excel to create an appointment
in Outlook. But I keep getting an error with the declaration "Dim
olApt As Outlook.AppointmentItem". It would say: "Compile Error: User-
defined type not defined". If I remove this declaration then an email
message (instead of an appointment) is created ! Please help !


Sub SetAppt()

Dim olApp As Object

On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")

If Err.Number = 429 Then
Set olApp = CreateObject("Outlook.Application")
End If

'Dim olApt As Outlook.AppointmentItem
Set olApt = olApp.CreateItem(olAppointmentItem)

With olApt
.Start = Date + 1 + TimeValue("19:00:00")
.End = .Start + TimeValue("00:30:00")
.Subject = "Piano lesson"
.Location = "The teachers house"
.Body = "Don't forget to take an apple for the teacher"
.BusyStatus = olBusy
.ReminderMinutesBeforeStart = 120
.ReminderSet = True
'.Save
.Display
End With

Set olApt = Nothing
Set olApp = Nothing

End Sub

Leith Ross[_765_]

Create Appointment in Outlook
 

;257763 Wrote:
I'm trying to use the following code in Excel to create an appointment
in Outlook. But I keep getting an error with the declaration "Dim
olApt As Outlook.AppointmentItem". It would say: "Compile Error: User-
defined type not defined". If I remove this declaration then an email
message (instead of an appointment) is created ! Please help !


Sub SetAppt()

Dim olApp As Object

On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")

If Err.Number = 429 Then
Set olApp = CreateObject("Outlook.Application")
End If

'Dim olApt As Outlook.AppointmentItem
Set olApt = olApp.CreateItem(olAppointmentItem)

With olApt
.Start = Date + 1 + TimeValue("19:00:00")
.End = .Start + TimeValue("00:30:00")
.Subject = "Piano lesson"
.Location = "The teachers house"
.Body = "Don't forget to take an apple for the teacher"
.BusyStatus = olBusy
.ReminderMinutesBeforeStart = 120
.ReminderSet = True
'.Save
.Display
End With

Set olApt = Nothing
Set olApp = Nothing

End Sub


Hello tianung,

Replace olAppointmentItem with the number 1 (one). Because you are
using late binding, Outlook's constants are available to you in code.


--
Leith Ross

Sincerely,
Leith Ross

'The Code Cage' (
http://www.thecodecage.com/)
------------------------------------------------------------------------
Leith Ross's Profile: http://www.thecodecage.com/forumz/member.php?userid=75
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=71980



All times are GMT +1. The time now is 10:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com