View Single Post
 
Old 06-23-2015, 03:48 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

In that case you probably won't want the following macro which will add the travel to any selected appointment
Code:
Sub AddTravel()
Dim olItem As AppointmentItem
Dim olTravel As AppointmentItem
Dim strTravel As String
Dim iTravelMinutes As Integer
    strTravel = InputBox("Enter the travel time in minutes for each journey", "Travel Time", 60)
    If IsNumeric(strTravel) Then
        iTravelMinutes = Val(strTravel)
        Set olItem = ActiveExplorer.Selection.Item(1)
        If olItem.Class = olAppointment Then
            Set olTravel = CreateItem(olAppointmentItem)
            With olTravel
                .MeetingStatus = olNonMeeting
                .Subject = "Travel to " & olItem.Subject
                .Start = DateAdd("n", -iTravelMinutes, olItem.Start)
                .Duration = iTravelMinutes
                .Save
            End With
            Set olTravel = CreateItem(olAppointmentItem)
            With olTravel
                .MeetingStatus = olNonMeeting
                .Subject = "Return travel from " & olItem.Subject
                .Start = olItem.End
                .Duration = iTravelMinutes
                .Save
            End With
        End If
    End If
lbl_Exit:
    Set olItem = Nothing
    Set olTravel = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote