gpt4 book ai didi

vba - 如何在 Outlook 中将约会添加到共享日历?

转载 作者:行者123 更新时间:2023-12-04 20:23:13 25 4
gpt4 key购买 nike

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

我拥有此共享日历的完整编辑权限。我所说的共享日历是指在该人的 Outlook 中创建一个常规日历,然后单击“共享”并将其通过电子邮件发送给他人。

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

如果我尝试插入其他人的日历,我的代码将无法找到“假日日历”

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

最佳答案

不是调用 Application.CreateItem/AppointmentItem.Move,而是直接使用 olFldr.Items.Add 创建项目。

关于vba - 如何在 Outlook 中将约会添加到共享日历?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37353404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com