2017-11-03 3 views
0

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 속성 만 포함되며 다른 관련 속성은 포함되지 않습니다.

사용자와 연결된 모든 이메일 주소를 가져 오는 방법이 있습니까? 아니면 기본 주소 만 받고 다른 주소는 가져갈 수 없습니까?

답변

0

실제로 흥미 롭습니다. 내 워크 스테이션으로 돌아 가면 Excel의 매크로를 조사해야합니다. 흥미 롭 군. 주의해야 할 점은 Excel에서 Exchange 매크로를 사용할 수 있으므로 Exchange 관리 셸에 설치 방법이 있다는 것입니다. 그 가정에서 잘못 될 수 있지만, 여기 어쨌든 간다 :

Import-csv <location of your source csv file> | Get-ADUser $_.Username -Properties Surname, GivenName, @{N="EmailAddresses"; E={$_.ProxyAddresses | % {[string]::join("|",$_)}}}, Title, Department} | Export-csv <location you want to save it> -NoTypeInformation 
: 당신이 CSV 파일에서 이미 확인하고자하는 모든 사용자가있는 경우

Get-MailboxDatabase -IncludePreExchange2013 | Get-mailbox | % { Get-ADUser $_.Alias -Properties Surname, GivenName, @{N="EmailAddresses"; E={$_.ProxyAddresses | % {[string]::join("|",$_)}}}, Title, Department} | Export-csv <location you want to save it> -NoTypeInformation 

는 다음과 같은 작업을 수행 할 수

CSV 파일에 조회하려는 계정의 사용자 이름이있는 "사용자 이름"이라는 열이 있는지 확인하십시오.

+0

OP가 호스팅 된 (Office 365) 사서함에 연결되거나 Exchange 관리 셸을 사용하여 액세스 권한이없는 사용자가 온 - 프레미어 서버 인 경우 OP가 작동하지 않습니다 (모든 경우의 99.9 %에서 발생 함)). –

+0

나는 OP가 EMS를 사용할 수있는 권한이 있다고 실제로 생각했다. 일반 사용자가 VBA 코드를 편집하지 않는다고 생각했습니다. O365까지는 Powershell 방식으로도 가능합니다. 나는 그것에 너무 많이 들여다 보지 못했지만 돈을 벌었습니다. – Joseph

0

AddressEntry.PropertyAccessor.GetProperty을 사용하여 PR_EMS_AB_PROXY_ADDRESSES MAPI 속성 (DASL 이름 http://schemas.microsoft.com/mapi/proptag/0x800F101F)을 읽어야합니다. 다중 값 속성이므로 문자열 배열을 반환합니다.

OutlookSpy (IMAPISession | QueryIdentity 단추 또는 IAddrBook을 클릭하고 문제의 GAL 항목까지 드릴 다운)에서 속성 및 해당 값을 볼 수 있습니다.

관련 문제