如何查找日历ID

时间:2018-02-14 14:29:26

标签: vba outlook outlook-vba

我需要找到Outlook日历的ID。这是一个包含许多贡献者/用户的公共日历,但未列为"共享"。

Outlook Calendars

我想自动将选定的日历导出到* .ics。 目前我只能导出我的默认文件夹:

 Set oNamespace = Application.GetNamespace("MAPI")
 Set oFolder = oNamespace.GetDefaultFolder(olFolderCalendar) 
 Set oCalendarSharing = oFolder.GetCalendarExporter
 oCalendarSharing.SaveAsICal "C:\calendar.ics"

我需要添加" ThisOne"到出口。 这些属性没有位置:

ThisOne-Properties

如何找到ID,因此我可以使用" GetFolderFromID()"?或者有更好的方法将日历包含在导出中或单独导出它吗?

编辑: 现在我认为我使用

获得了Calendar-ID
Set oNamespace = Application.GetNamespace("MAPI")
Set oFolderPicked = oNamespace.PickFolder
Set oFolder = oNamespace.GetFolderFromID(oFolderPicked.EntryID, oFolderPicked.StoreID)
Set oCalendarSharing = oFolder.GetCalendarExporter

但是这会在最后一行(GetCalendarExporter)抛出异常:

Exception

如果我在GUI中导出(文件 - >保存),它可以正常工作......

(后来我不想使用PickFolder,只是将EntryID硬编码到脚本中)

2 个答案:

答案 0 :(得分:1)

打开Outlook->转到所选择的日历-> Alt F11->立即窗口->键入以下内容,然后按Enter。

? ActiveExplorer.CurrentFolder.EntryID

答案 1 :(得分:0)

这演示了如何获取文件夹的EntryID。

Option Explicit

Sub entryIDFromActiveExplorer()

Dim entryIDStr As String

Dim uPrompt As String
Dim uTitle As String
Dim uDefault As String
Dim msg As String

' Select a folder in the folder view
' Do not use the calendar view

entryIDStr = ActiveExplorer.CurrentFolder.entryID

uPrompt = "To hardcode the entryID of the " & _
          Session.GetFolderFromID(entryIDStr) & _
          " folder, copy this ID"

' Copy from the immediate pane
Debug.Print uPrompt
Debug.Print entryIDStr

uTitle = Session.GetFolderFromID(entryIDStr)
uDefault = entryIDStr

msg = InputBox(Prompt:=uPrompt, Title:=uTitle, Default:=uDefault)

End Sub


Sub entryIDFromPickfolder()

' If you do not want to select a folder
'  in the normal way, from the GUI

Dim oFolderPicked As folder

Dim entryIDStr As String

Dim uPrompt As String
Dim uTitle As String
Dim uDefault As String
Dim msg As String

Set oFolderPicked = Session.PickFolder

If Not oFolderPicked Is Nothing Then

    entryIDStr = oFolderPicked.entryID

    uPrompt = "To hardcode the entryID of the " & _
              Session.GetFolderFromID(entryIDStr) & _
              " folder, copy this ID"

    ' Copy from the immediate pane
    Debug.Print uPrompt
    Debug.Print entryIDStr

    Set ActiveExplorer.CurrentFolder = Session.GetFolderFromID(entryIDStr)
    DoEvents

    uTitle = Session.GetFolderFromID(entryIDStr)
    uDefault = entryIDStr

    msg = InputBox(Prompt:=uPrompt, Title:=uTitle, Default:=uDefault)

End If

ExitRoutine:
    Set oFolderPicked = Nothing

End Sub