Reputation: 885
I am trying to display a custom UI for entering information on Outlook appointments.
I have this for existing appointments.
I would like to create new appointments by having the user click and drag to select a time range and then trigger the macro. (This works for the built in New Appointment command in Outlook.)
How do I programmatically get the time range selected to create a new appointment via VBA code?
Upvotes: 3
Views: 3359
Reputation: 5911
Better way is to use the SelectedStartTime
and SelectedEndTime
https://msdn.microsoft.com/en-us/library/office/ff869571.aspx
Public Sub GetNewAppt()
Dim exp As Explorer: Set exp = Outlook.ActiveExplorer
Dim mfCalFolder As MAPIFolder
Set mfCalFolder = exp.CurrentFolder
Dim vw As View: Set vw = exp.CurrentView
If vw.ViewType = olCalendarView Then
With vw
Dim objAppt As AppointmentItem
Set objAppt = mfCalFolder.Items.Add
objAppt.Start = .SelectedStartTime
objAppt.End = .SelectedEndTime
objAppt.Display
End With
End If
End Sub
I trigger this with a custom button on the ribbon. Didn't test this 2007 or prior.
Upvotes: 1