2016-06-27 9 views
1

ユーザー資格情報を使用してOutlook(Exchange)カレンダーに接続し、カレンダーデータを解析してスプレッドシートに出力するExcelマクロを作成しています。ローカルのOutlookアプリケーションからカレンダーデータを取得できましたが、別のアカウントにログインする方法がわかりません。これは可能ですか?交換カレンダーにアクセスするには、何らかの方法が必要です。私はすでにインターネット上で収集したことから、私はMAPIを使用できるかもしれませんか?私はちょうどこの場合のためにどのようにわからない。Exchangeの予定表にExcelでログオンするには

Sub ListAppointments() 
'Dim mapi_session As MSMAPI.MAPISession 
'Set mapi_session = CreateObject("MSMAPI.MAPISession") 
Dim olApp As Object 
Dim olNS As Object 
Dim olFolder As Object 
Dim olApt As Object 
Dim myStart As Date 
Dim myEnd As Date 
Dim NextRow As Long 
Dim today, date1, date2 
today = VBA.Format(Date, "yyyy-mm-dd") 

myStart = VBA.Format(Year(today) & "-" & Month(today) & "-01", "yyyy-mm-dd") 
myEnd = DateAdd("m", 3, myStart) 
date1 = InputBox("Enter range beginning date", , myStart) 
date2 = InputBox("Enter range end date", , myEnd) 
Set olApp = CreateObject("Outlook.Application") 

Set olNS = olApp.GetNamespace("MAPI") 
olNS.Logon "", "", False, True 
Set olFolder = olNS.GetDefaultFolder(9) 'olFolderCalendar 

Range("A1:D1").Value = Array("Subject", "Start", "End", "Location") 

NextRow = 2 
For Each olApt In olFolder.Items 
    If olApt.Start >= myStart And olApt.End <= myEnd Then 
     Cells(NextRow, "A").Value = olApt.Subject 
     Cells(NextRow, "B").Value = olApt.Start 
     Cells(NextRow, "C").Value = olApt.End 
     Cells(NextRow, "D").Value = olApt.Location 
     NextRow = NextRow + 1 
    End If 
Next olApt 

Set olApt = Nothing 
Set olFolder = Nothing 
Set olNS = Nothing 
Set olApp = Nothing 

Columns.AutoFit 

End Sub 

これまでのところ、私はローカルの見通しデータを取得できます。

答えて

1

olNS.CreateRecipient/olNS.GetSharedDefaultFolder(..., olFolderCalendar)を使用して、別のExchangeメールボックスの予定表フォルダを開きます。

関連する問題