How to adjust appointment start/end times in Outlook

Posted on 2009-04-06
Last Modified: 2012-05-06
1st Question from Newbie...


I have a number of various appointments that I create very often in my calendar and so have a macro and a series of buttons to help me do this.

The "CreateAppt" macro code is below and the code for each of the buttons goes like this:

Sub TrainLondon()

Call CreateAppt("Train: Bath Spa to London", 2, "Travel, Time & Expenses", True, 30, "")

End Sub

My problem is that I want to pick up when a train journey is selected and substitute the user selected start/end times (typically 06:30 and 08:30) for the actual train times of 06:43 and 08:29 ... I cannot seem to find right construct to set the objAppt.Start and objAppt.End values correctly. Obviously I need to capture the date the user selected and then use that to augment the start/end times.

Any help always appreciated.


Private Sub CreateAppt(strSubject, intBusyStatus, strCategories, bolRemindMe, intRemindMe, strBodyText)


    Dim objExpl As Outlook.Explorer

    Dim objFolder As Outlook.MAPIFolder

    Dim objCB As Office.CommandBarButton

    Dim objAppt As Outlook.AppointmentItem

    Dim objApptCustom As Outlook.AppointmentItem

    On Error Resume Next


    Set objExpl = Application.ActiveExplorer

    If Not objExpl Is Nothing Then

        Set objFolder = objExpl.CurrentFolder

        If objFolder.DefaultItemType = olAppointmentItem Then

            Set objCB = objExpl.CommandBars.FindControl(, 1106)

            If Not objCB Is Nothing Then


                Set objAppt = Application.ActiveInspector.CurrentItem

                Set objApptCustom = objFolder.Items.Add("IPM.Appointment")

                With objApptCustom

                    .Subject = strSubject

                    .Start = objAppt.Start

                    .End = objAppt.End

                    If intBusyStatus = 0 Then .BusyStatus = olFree

                    If intBusyStatus = 1 Then .BusyStatus = olTentative

                    If intBusyStatus = 2 Then .BusyStatus = olBusy

                    If intBusyStatus = 3 Then .BusyStatus = olOutOfOffice

                    .Categories = strCategories

                    .ReminderSet = bolRemindMe

                    If bolRemindMe = True Then

                        .ReminderMinutesBeforeStart = intRemindMe

                    End If

                    .Body = strBodyText


                End With


            End If


            MsgBox ("You must be in your Calendar and select the Start/End times of the appointment.")

        End If

    End If


    Set objCB = Nothing

    Set objAppt = Nothing

    Set objApptCustom = Nothing

    Set objFolder = Nothing

    Set objExpl = Nothing

End Sub

Open in new window

Question by:Charltp5
  • 3
  • 2
LVL 76

Expert Comment

by:David Lee
Comment Utility
Hi, Charltp5.

Sorry, but I'm not clear on the issue.  Are you saying that you need to prepend the date to the user selected start time?  

Author Comment

Comment Utility
Say I select an appointment slot on 08/04/09 of 08:00 to 08:30 and I click on the button for the TrainLondon sub routine, in the CreateAppt routine I want to recognise it and instead of creating the appointment for 08:00 to 08:30 I want to create it for 06:43 to 08:29 on 08/04/09. When I select the same slot on 12/04/09 I want to create the appointment for 06:43 to 08:29 on 12/04/09.

So the date will vary depending on the objAppt value but the Start and End times will be change to the actual train times and not those the user has selected.

At present I select the appointment slot of dd/mm/yyyy and 06:30 to 08:30 and that is how the appointment is created. I want to change those times.

Something like...

If strSubject = "blah blah" Then
  objAppt.Start = "dd/mm/yyyy 06:43"
  objAppt.End = "dd/mm/yyyy 08:29"
End If
LVL 76

Accepted Solution

David Lee earned 125 total points
Comment Utility
If the date is already filled in and you just want to change the time then use something like this

    objAppt.Start = Format(objAppt.Start,"dd/mm/yy") & " 06:43"

Instead of setting End I recommend setting the Duration value instead.  It'll calculate End for you.

Author Closing Comment

Comment Utility
Excellent! Thanks very much - worked a treat.
LVL 76

Expert Comment

by:David Lee
Comment Utility
You're welcome.  Glad I could help.

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Email signatures have numerous marketing benefits. Here are 8 top reasons to turn your email signature into a marketing channel.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now