簡體   English   中英

Excel VBA在非默認日歷中創建會議

[英]Excel VBA create Meeting in Non-Default Calendar

如何使用VBA代碼在Outlook中非默認電子郵件地址的非默認日歷上創建會議?

我創建的代碼在默認電子郵件地址的默認日歷中創建邀請:

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

我什至嘗試更改日歷時最接近的就是此參考 為了開始嘗試在我的示例中實現此代碼,我進行了以下測試

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.com\Calendar").Items
Debug.Print (Items.Parent.FolderPath)
Debug.Print ("End")
End Sub

但是我收到運行時錯誤'91':未在行Set Items = GetFolderPath(“ otheremail@contoso.com \\ Calendar”)上設置對象變量或With塊變量。

UPDATE

此代碼運行:

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文件夾集合上創建日歷條目呢?

此代碼將在Outlook中的非默認帳戶中的非默認日歷上創建約會。 希望這可以幫助將來的其他人:

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

暫無
暫無

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

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