PDA

View Full Version : Automatically updating fields each time an appointment is created



Noam_IBM
12-23-2020, 05:16 AM
Hello,
I'm looking to create a macro which will automatically update 3 fields each time I create a new appointment -

"Show as" = Free
"Reminder" = 0 minutes
"Category" = the blue category

Is the above possible with a Macro?
Thank you,

-Noam

gmayor
12-23-2020, 10:33 PM
It is easy enough to create an appointment with a macro, and add whatever options you wish:


Option Explicit
'Graham Mayor - https://www.gmayor.com - Last updated - 24 Dec 2020
Sub TestMeeting()
CreateAppointment "Strategy Meeting", "Conference Room", "12/29/2017", "14:00", 30, True, "John Smith", "Bill Jones", "Meeting to discuss planning for Christmas holidays", olNonMeeting
lbl_Exit:
Exit Sub
End Sub

Sub CreateAppointment(strSubject As String, _
strLocation As String, _
strBodyText As String, _
strDate As String, _
strTime As String, _
Optional iMinutes As Integer, _
Optional bAllDay As Boolean = True, _
Optional strName1 As String, _
Optional strName2 As String, _
Optional lngStatus As Long = olNonMeeting)

Dim olItem As AppointmentItem
Dim rRequiredAttendee As Recipient
Dim rOptionalAttendee As Recipient
Dim olInsp As Outlook.Inspector
Dim wdDoc As Object
Dim oRng As Object

Set olItem = CreateItem(olAppointmentItem)
With olItem
.MeetingStatus = lngStatus
.Subject = strSubject
.Location = strLocation
.Start = strDate & Chr(32) & strTime ' & strAMPM
.Duration = iMinutes
.AllDayEvent = bAllDay

'add other options as required here

Set rRequiredAttendee = .Recipients.Add(strName1)
rRequiredAttendee.Type = olRequired
Set rOptionalAttendee = .Recipients.Add(strName2)
rOptionalAttendee.Type = olOptional
.Display
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oRng = wdDoc.Range
oRng.Text = strBodyText
End With
Set olItem = Nothing
Set rRequiredAttendee = Nothing
Set rOptionalAttendee = Nothing
Set olInsp = Nothing
Set wdDoc = Nothing
Set oRng = Nothing
lbl_Exit:
Exit Sub
End Sub