java outlook日历_从 Excel 在特定的日历中创建 Outlook 约会

Dmitry 指出了如何在 Excel 的共享日历中创建 appointment/meeting 的功能。他的帖子对我有很大帮助,因为在共享日历上如何创建约会似乎没有很好的答案。我遍历众多论坛以获取答案,但提出的建议很少。根据他的回答,我能够使其工作。以下是我放在一起的示例脚本。这是我所用的 stripped-down 版本,但是我确实测试了此示例,并且可以正常工作。只需确保在 Excel VBA 编辑器的“工具”->“参考”菜单项中选择了 Outlook 库。

Sub SendInvitationAsUser()

Rcpts = "user@test.com; user2@test.com, etc@test.com" ' These can be in other formats that Outlook understands like display name.

Subject = "Meeting sent from shared calendar"

' Creates Outlook instance

Set OutApp = CreateObject("Outlook.Application")

Dim myNamespace As Outlook.Namespace

Dim myRecipient As Outlook.Recipient

Dim objfolder As Outlook.Folder

Set myNamespace = OutApp.GetNamespace("MAPI")

Set myRecipient = myNamespace.CreateRecipient("Smith, John Q") 'The invite will come from this user's mailbox

myRecipient.Resolve

If myRecipient.Resolved Then

Set objfolder = myNamespace.GetSharedDefaultFolder(myRecipient, olFolderCalendar) 'Sets folder where appt will be created

Else

ok = MsgBox("Unable to resolve the name of the sender.", vbCritical, "Error")

Exit Sub

End If

Set OutlookAppt = objfolder.Items.Add(olAppointmentItem) 'Creates appointment in shared calendar

' Edit Outlook appointment, convert to meeting invitation by adding recipients.

With OutlookAppt

.MeetingStatus = olMeeting

.Subject = Subject

.Start = #1/1/2018 8:00:00 AM#

.End = #1/1/2018 9:00:00 AM#

.Location = "Conference Room 1"

.RequiredAttendees = Rcpts

End With

'Use Word to do fancy formatting of body text. Example below is basic but a lot of formatting via VBA is possible.

Set WordApp = CreateObject("Word.Application")

Set WordDoc = WordApp.Documents.Add

Set DocSelection = WordApp.Selection

WordApp.Visible = True

WordDoc.Activate ' You want to see the window, right?

DocSelection.Font.Name = "Arial" ' Everything is Arial.

DocSelection.Font.Size = "10" ' Everything is size 10.

DocSelection.ParagraphFormat.SpaceAfter = "0" ' No line spacing.

DocSelection.ParagraphFormat.SpaceBefore = "0" ' No line spacing.

DocSelection.TypeText ("Please plan to attend my meeting.")

WordDoc.Content.Copy

OutlookAppt.Display

Set TargetApptDoc = OutlookAppt.GetInspector.WordEditor

TargetApptDoc.Range(0, 0).Paste

WordDoc.Close savechanges:=False

WordApp.Quit

End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值