VBscript outlook表单在特定日历中创建会议

时间:2017-08-24 18:55:22

标签: vba vbscript outlook outlook-vba outlook-2010

过去几天我一直在研究这个问题。我的VBscript代码有效,将在Outlook的默认日历中创建会议。我似乎无法弄清楚的部分是如何在名为“Test”的自定义日历中进行会议。此日历列在“我的日历”下。有什么建议吗?

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 个答案:

答案 0 :(得分:1)

将项目添加到非默认日历中。

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