简体   繁体   English

将约会添加到日历时键入不匹配

[英]Type mismatch on adding appointment to calendar

I'm starting in on a project that requires me to add appointments to a shared calendar.我正在开始一个项目,该项目要求我将约会添加到共享日历。 I've never used the Outlook object model before, but I've managed to get the procedure down for adding to my default calendar via the following sub:我以前从未使用过 Outlook 对象模型,但我已经设法通过以下子项完成了添加到默认日历的过程:

Option Explicit

Sub caltest()

Dim O As Outlook.Application
Set O = New Outlook.Application

Dim ONS As Outlook.Namespace
Set ONS = O.GetNamespace("MAPI")

Dim myCalendar As Outlook.Folder
Set myCalendar = ONS.GetDefaultFolder(olFolderCalendar)

Dim myapt As Outlook.AppointmentItem
Set myapt = myCalendar.Items.Add([AppointmentItem])

With myapt
    .Start = DateValue("4/2/2018") + TimeValue("11:30:00")
    .End = DateValue("4/2/2018") + TimeValue("12:00:00")
    .Location = "nowhere"
    .Subject = "test"
    .Body = "something important"
    .Save
End With

End Sub

However, if I try another calendar, I suddenly get a Type Mismatch error.但是,如果我尝试另一个日历,我会突然收到类型不匹配错误。 I'm sure it's just a gap in my understanding of the Folder object itself.我确定这只是我对 Folder 对象本身的理解的一个空白。

Option Explicit

Sub caltest()

Dim O As Outlook.Application
Set O = New Outlook.Application

Dim ONS As Outlook.Namespace
Set ONS = O.GetNamespace("MAPI")

Dim myCalendar As Outlook.Folder
Set myCalendar = ONS.Folders("videoconferencing@example.org")  'changed this line

Dim myapt As Outlook.AppointmentItem
Set myapt = myCalendar.Items.Add([AppointmentItem])  'line throws type mismatch

With myapt
    .Start = DateValue("4/2/2018") + TimeValue("11:30:00")
    .End = DateValue("4/2/2018") + TimeValue("12:00:00")
    .Location = "nowhere"
    .Subject = "test"
    .Body = "something important"
    .Save
End With

End Sub

What about that Set myapt line is incorrect?Set myapt行不正确呢?

PS I'm self-taught so feel free to correct me on bad syntax or other bits & bobs. PS 我是自学的,所以请随时纠正我的语法错误或其他一些问题。

I changed我变了

Set myCalendar = ONS.Folders("videoconferencing@example.org")

to

Set myCalendar = ONS.Folders("videoconferencing@example.org").Folders("Calendar") . Set myCalendar = ONS.Folders("videoconferencing@example.org").Folders("Calendar")

Wish I would have tried that before posting!希望我能在发布前尝试过!

I am not sure what AppointmentItem is on the following line.我不确定下面一行中的 AppointmentItem 是什么。

Set myapt = myCalendar.Items.Add([AppointmentItem])

Did you mean olAppointmentItem ( = 1)?你是说 olAppointmentItem ( = 1) 吗?

Set myapt = myCalendar.Items.Add(olAppointmentItem)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM