Solved

How to adjust appointment start/end times in Outlook

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

Hi,

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.

Thanks!

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
                objCB.Execute
                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
                    .Save
                End With
                objAppt.Delete
            End If
        Else
            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

0
Comment
Question by:Charltp5
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 24076143
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?  
0
 
LVL 1

Author Comment

by:Charltp5
ID: 24076385
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
0
 
LVL 76

Accepted Solution

by:
David Lee earned 125 total points
ID: 24076901
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.
0
 
LVL 1

Author Closing Comment

by:Charltp5
ID: 31566946
Excellent! Thanks very much - worked a treat.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24077711
You're welcome.  Glad I could help.
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to Standardise Exchange Webmail email link? 6 67
Saving battery power with emails 5 63
clicking a shape in a frame array vb6 3 45
Exchange on iphone 16 57
Are you having trouble connecting or getting your iPhone / Samsung device(s) to sync with Microsoft Exchange Server?   What have you tried?   What haven't you tried?
In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
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…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

770 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