VBscript outlook form creating meeting in specific

2020-05-06 16:41发布

I've been working on this the past few days. My VBscript code works and will create a meeting in the default calendar in Outlook. The part I can't seem to figure out is how to have the meeting made in a custom calendar named "Test". This calendar is listed under "My Calendars". Any advice?

Sub commandbutton1_Click()                                  

If CommandButton1 = False Then

Const olFolderCalendar = 9
Const olAppointmentItem = 1
Const olOutOfOffice = 3

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
' bottom line original:  Set objCalendar = objNamespace.GetDefaultFolder(olFolderCalendar) 

Set objCalendar = objNamespace.GetDefaultFolder(olFolderCalendar) '.Parent.Items("Test")
Set objApptItems = objCalendar.Items

objApptItems.IncludeRecurrences = True
objApptItems.Sort "[Start]"

Set objHoliday = objOutlook.CreateItem(olAppointmentItem) 
                            'creating day off appointment
objHoliday.Subject = "Boxing Day"
objHoliday.Start = Item.UserProperties("DateText")
objHoliday.End = Item.UserProperties("EndDate")
objHoliday.AllDayEvent = True
objHoliday.ReminderSet = False
objHoliday.BusyStatus = olOutOfOffice
objHoliday.Save

                            'testing confirmation email
Set objMail = objOutlook.CreateItem(o)
    'Item.To
objMail.to = Item.To    'UserProperties("From")
objMail.Subject = "Confirmation: Requested Day(s) Off Approved"
objMail.Body = "Congratulations, your requested day(s) off have been Approved!"
objMail.Send

                            'closes email after hitting button
'For i = objOutlook.Inspectors.count To 1 Step -1
'        objOutlook.Inspectors.Item(i).Close True
'    Next

End If
End Sub

1条回答
家丑人穷心不美
2楼-- · 2020-05-06 17:20

Items are added to non-default calendars.

Sub Add_To_NonDefault_Folder()

    Dim objNameSpace As NameSpace
    Dim objCalendar As Folder
    Dim objHoliday As AppointmentItem

    Set objNameSpace = GetNamespace("MAPI")
    Set objCalendar = objNameSpace.GetDefaultFolder(olFolderCalendar).Folders("Test")

    Set objApptItems = objCalendar.items
    Set objHoliday = objCalendar.items.Add(olAppointmentItem)

    objHoliday.Subject = "Appt test"
    objHoliday.SAVE

End Sub
查看更多
登录 后发表回答