Excel VBA 在非默认日历中创建会议 [英] Excel VBA create Meeting in Non-Default Calendar

查看:12
本文介绍了Excel VBA 在非默认日历中创建会议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 VBA 代码在 Outlook 中非默认电子邮件地址的非默认日历上创建会议?

How do I create a Meeting on the non default calendar of the non default email address in outlook using VBA code?

我在默认电子邮件地址的默认日历中创建邀请的代码:

The code that I have creates the invites in the default calendar of the default email address:

Sub CreateAppointmentOutlook()

Dim oApp As Outlook.Application
Dim oApt As Outlook.AppointmentItem
Dim oRecip As Outlook.Recipient
Dim i As Long
Dim lastRow As Long
Dim ws As Worksheet
Dim wb As ThisWorkbook
Set oApp = New Outlook.Application

Set ws = ActiveWorkbook.Worksheets("Sheet1")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

For i = 1 To lastRow
    Set oApt = oApp.CreateItem(olAppointmentItem)
    oApt.MeetingStatus = olMeeting
    Debug.Print (ws.Cells(i, 1).Value)
    With oApt
        .Subject = "Test"
        ' do some other stuff
    End With
Next i
End Sub

我什至尝试更改日历最接近的是这个 参考.为了开始尝试在我的示例中实现这段代码,我做了以下测试

The closest I could come to even attempting to change calendar was this reference. To even begin to try to implement this code in my example I did the below as a test

Sub Whatever()
Dim olApp As Object
Set olApp = GetObject(, "Outlook.Application")
Dim ns As Outlook.Namespace

Set ns = olApp.GetNamespace("MAPI")
Dim Items As Object
Set Items = GetFolderPath("otheremail@contoso.comCalendar").Items
Debug.Print (Items.Parent.FolderPath)
Debug.Print ("End")
End Sub

但我收到运行时错误91":对象变量或块变量未在线设置 Set Items = GetFolderPath("otheremail@contoso.comCalendar").Items

But I get a Run-time error '91' : Object variable or With block variable not set on line Set Items = GetFolderPath("otheremail@contoso.comCalendar").Items

更新

此代码运行:

Sub Whatever()
Dim olApp As Object
Set olApp = GetObject(, "Outlook.Application") 
Dim oApt As Outlook.AppointmentItem

Dim ns As Outlook.Namespace
Dim oFolder As Outlook.Folder

Set ns = olApp.GetNamespace("MAPI")
Set oFolder = ns.Folders("otheremail@contoso.com")

Dim CalItems As Outlook.Items
Set CalItems = oFolder.Items

End Sub

但是如何在这个其他 CalItems 文件夹集合上创建日历条目?

But how then to create a calendar entry on this other CalItems folder collection?

推荐答案

此代码将在 Outlook 的非默认帐户中的非默认日历上创建约会.希望这可以帮助其他人将来:

This code will create a Appointment on non default calendar in a non default account in Outlook. Hope this helps someone else out in future:

Sub Whatever()
Dim olApp As Object
Set olApp = GetObject(, "Outlook.Application")
Dim oApt As Outlook.AppointmentItem
Dim ns As Outlook.Namespace
Dim recip As Outlook.Recipient
Dim oFolder As Outlook.Folder
Set ns = olApp.GetNamespace("MAPI")
Set recip = ns.CreateRecipient("otheremail@contoso.com")

If recip.Resolve Then
    Set otherFolder = ns.GetSharedDefaultFolder(recip, olFolderCalendar)
End If

Set oApt = otherFolder.Items.Add(olAppointmentItem)

oApt.MeetingStatus = olMeeting
    With oApt
        .Subject = "Test"
        .Start = "15/04/2019 09:00"
        .End = "15/04/2019 09:10"
        .Location = "The Business Meeting Room"
        .Recipients.Add ("user@contoso.com")
        .Send
    End With
End Sub

这篇关于Excel VBA 在非默认日历中创建会议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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