Excel에서 VBA를 사용하여 Outlook.ExchangeUser
개체에서 연락처 정보를 가져 오려고합니다. 그러나 지금까지 각 사용자에 대한 기본 SMTP 주소를 얻을 수 있었지만 가능한 경우 각 계정에 연결된 모든 전자 메일 주소를 얻고 싶습니다. 우리는 최근 새 브랜드를 변경하고 새로운 도메인을 얻었으므로 새 이메일 주소가 기본 전자 메일 주소가되었습니다. 그러나 이전 주소를 모두 함께 추출 할 수 있습니다.이 주소는 여전히 사용할 수 있기 때문에 (일부는 더 오래된 이메일 주소). 이건 정말 잘 작동VBA를 사용하여 기본 SMTP 주소가 아닌 다른 Microsoft Exchange 전자 메일 주소를 얻는 방법
Sub GetAllGALMembers()
Dim i As Long, j As Long, lastRow As Long
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olGAL As Outlook.AddressList
Dim olEntry As Outlook.AddressEntries
Dim olMember As Outlook.AddressEntry
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olGAL = olNS.GetGlobalAddressList()
'Set Up Excel
Dim wb As Workbook, ws As Worksheet
'set the workbook:
Set wb = ThisWorkbook
'set the worksheet where you want to post Outlook data:
Set ws = wb.Sheets("Sheet1")
'clear all current entries
Cells.Select
Selection.ClearContents
'set and format headings in the worksheet:
ws.Cells(1, 1).Value = "First Name"
ws.Cells(1, 2).Value = "Last Name"
ws.Cells(1, 3).Value = "Email"
ws.Cells(1, 4).Value = "Title"
ws.Cells(1, 5).Value = "Department"
Application.ScreenUpdating = False
With ws.Range("A1:E1")
.Font.Bold = True
.HorizontalAlignment = xlCenter
End With
Set olEntry = olGAL.AddressEntries
On Error Resume Next
'first row of entries
j = 2
' loop through dist list and extract members
For i = 1 To olEntry.Count
Set olMember = olEntry.Item(i)
If olMember.AddressEntryUserType = olExchangeUserAddressEntry Then
'add to worksheet
ws.Cells(j, 1).Value = olMember.GetExchangeUser.LastName
ws.Cells(j, 2).Value = olMember.GetExchangeUser.FirstName
ws.Cells(j, 3).Value = olMember.GetExchangeUser.PrimarySmtpAddress
ws.Cells(j, 4).Value = olMember.GetExchangeUser.JobTitle
ws.Cells(j, 5).Value = olMember.GetExchangeUser.Department
j = j + 1
End If
Next i
Application.ScreenUpdating = True
'determine last data row, basis column B (contains Last Name):
lastRow = ws.Cells(Rows.Count, "B").End(xlUp).Row
'format worksheet data area:
ws.Range("A2:E" & lastRow).Sort Key1:=ws.Range("B2"), Order1:=xlAscending
ws.Range("A2:E" & lastRow).HorizontalAlignment = xlLeft
ws.Columns("A:E").EntireColumn.AutoFit
wb.Save
'quit the Outlook application:
applOutlook.Quit
'clear the variables:
Set olApp = Nothing
Set olNS = Nothing
Set olGAL = Nothing
End Sub
그러나 내가 할 수있는 모든이 .GetExchangeUser.PrimarySmtpAddress
속성을 통해, 각 사용자에 대한 하나의 이메일 주소 :
동료
나에게 작업을하려면 다음 코드를했다.Outlook Object Model Reference for the ExchangeUser Object을 확인했지만 여기에는 ExchangeUser.PrimarySmtpAddress
속성 만 포함되며 다른 관련 속성은 포함되지 않습니다.
사용자와 연결된 모든 이메일 주소를 가져 오는 방법이 있습니까? 아니면 기본 주소 만 받고 다른 주소는 가져갈 수 없습니까?
OP가 호스팅 된 (Office 365) 사서함에 연결되거나 Exchange 관리 셸을 사용하여 액세스 권한이없는 사용자가 온 - 프레미어 서버 인 경우 OP가 작동하지 않습니다 (모든 경우의 99.9 %에서 발생 함)). –
나는 OP가 EMS를 사용할 수있는 권한이 있다고 실제로 생각했다. 일반 사용자가 VBA 코드를 편집하지 않는다고 생각했습니다. O365까지는 Powershell 방식으로도 가능합니다. 나는 그것에 너무 많이 들여다 보지 못했지만 돈을 벌었습니다. – Joseph