簡體   English   中英

將約會添加到日歷時鍵入不匹配

[英]Type mismatch on adding appointment to calendar

我正在開始一個項目,該項目要求我將約會添加到共享日歷。 我以前從未使用過 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

但是,如果我嘗試另一個日歷,我會突然收到類型不匹配錯誤。 我確定這只是我對 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

Set myapt行不正確呢?

PS 我是自學的,所以請隨時糾正我的語法錯誤或其他一些問題。

我變了

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

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

希望我能在發布前嘗試過!

我不確定下面一行中的 AppointmentItem 是什么。

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

你是說 olAppointmentItem ( = 1) 嗎?

Set myapt = myCalendar.Items.Add(olAppointmentItem)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM