I am attempting to generate an appointment from a VBA macro and put it into a calendar in Outlook. my code is below…
Sub CommandButton1_Click()
Const olAppointmentItem As Long = 1
Dim olapp As Object
Dim OLNS As Object
Dim OLAppointment As Object
On Error Resume Next
Set olapp = GetObject(, "Outlook.Application")
If olapp Is Nothing Then Set olapp = CreateObject("Outlook.Application")
On Error GoTo 0
If Not olapp Is Nothing Then
Set OLNS = olapp.GetNamespace("MAPI")
OLNS.Logon
Set OLAppointment = olapp.CreateItem(olAppointmentItem)
OLAppointment.Subject = "Request for Leave"
OLAppointment.Start = TimeValue(TextBox7.Text)
OLAppointment.End = TimeValue(TextBox10.Text)
OLAppointment.Location = "Leave"
OLAppointment.Body = "Request for Leave"
OLAppointment.Save
'Set OLAppointment = olapp.Move(olfolder)
Set OLAppointment = Nothing
Set OLNS = Nothing
Set olapp = Nothing
End If
End Sub
The problem is that the appointment gets dated to begin on the ‘Sat 30/12/1899’ and only lasts for half an hour when i need it to last for the duration of days between the two dates as an all day appointment throughout, (Start date : TextBox7)(End date : TextBox10).
Another issue is how would i send this request to someone?
The appointment details are from an Excel UserForm’s text fields
Thanks
TimeValue doesn’t seem to allow you to include the date, only the time of day. If you set the start and end times with the below formats, for example, then it does work.