如何在Outlook中向共享日历添加约会? [英] How to Add an Appointment to a Shared Calendar in Outlook?

查看:553
本文介绍了如何在Outlook中向共享日历添加约会?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个从 .CSV 文件获取的约会,该约会带有主题和日期,并将其放置在其他人的共享日历中。

I am attempting to create an appointment taken from a .CSV file with Subject and Date and place this in someone else's shared calendar.

我对此共享日历具有完全编辑者的权限。所谓共享日历,是指在用户的Outlook中制作的常规日历,然后单击共享并通过电子邮件将其发送给他人。

I have full editor's permissions for this shared calendar. By shared calendar I mean, a regular calendar made in the person's Outlook and clicking "Share" and emailing it to others.

Sub ImportAppointments(full_path As String)

'Initialize variables
Dim exlApp As Excel.Application
Dim exlWkb As Workbook
Dim exlSht As Worksheet
Dim rng As Range
Dim itmAppt As Outlook.AppointmentItem

' Create reference to Excel
Set exlApp = New Excel.Application

' Select file path, currently hardcoded to one directory, change as needed
Dim strFilepath As String
'strFilepath = "P:\Holiday Calendar\Holiday_Calendar_Data.csv"
strFilepath = full_path

' Select workbook (the above .csv file) and select the first worksheet as the data sheet
Set exlSht = Excel.Application.Workbooks.Open(strFilepath).Worksheets(1)

' Initialize variables
Dim iRow As Integer
Dim iCol As Integer
Dim oNs As Namespace
Dim olFldr As Outlook.MAPIFolder
Dim objOwner As Outlook.Recipient

' Allow accessing data stored in the user's mail stores in Outlook
Set oNs = Outlook.GetNamespace("MAPI")

' Set share calender owner
Set objOwner = oNs.CreateRecipient("calvin@xyz.ca")
    objOwner.Resolve

If objOwner.Resolved Then

    ' Set up non-default share folder location
    Set olFldr = oNs.GetSharedDefaultFolder(objOwner, olFolderCalendar).Folders("Holiday Calendar")

End If

' Start point
iRow = 2
iCol = 1

' Loop through each calendar entry
While exlSht.Cells(iRow, 1) <> ""

    Set itmAppt = Outlook.CreateItem(olAppointmentItem)

    ' Set appointment Subject, ie (Vacation, Sick Day, Half-Day, etc.)
    itmAppt.Subject = exlSht.Cells(iRow, 1)

    ' Set Date of Event
    itmAppt.Start = exlSht.Cells(iRow, 2)

    ' Force All Day Event
    itmAppt.AllDayEvent = True

    ' Save appointment
    itmAppt.Save

    ' Advance pointer to next row
    iRow = iRow + 1

    ' Transfer appointment into shared calendar folder
    itmAppt.Move olFldr

Wend

' Close everything
Excel.Application.Workbooks.Close
exlApp.Quit
Set exlApp = Nothing
Set olFldr = Nothing
Set itmAppt = Nothing

End Sub

如果我尝试使用其他人的日历插入代码,则我的代码将找不到假日日历

My code fails to find the "Holiday Calendar" if I try to insert at someone else's calendar with

Set olFldr = oNs.GetSharedDefaultFolder(objOwner, olFolderCalendar).Folders("Holiday Calendar")


推荐答案

调用 Application.CreateItem / AppointmentItem.Move ,直接使用 olFldr.Items创建项目。添加

Instead of calling Application.CreateItem / AppointmentItem.Move, create the item directly using olFldr.Items.Add.

这篇关于如何在Outlook中向共享日历添加约会?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆