これにより、必要なものが得られます。
Private Function GetFullName(inAlias As String) As String
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olAdd As Outlook.AddressEntries
Dim olMem As Outlook.AddressEntry
Dim olLst As Outlook.AddressList
Dim olAlias As String
On Error Resume Next
Set olApp = New Outlook.Application
On Error GoTo 0
If olApp Is Nothing Then
GetFullName = "Source not available"
Exit Function
End If
Set olNS = olApp.GetNamespace("MAPI")
Set olLst = olNS.GetGlobalAddressList
Set olAdd = olLst.AddressEntries
For Each olMem In olAdd
On Error Resume Next
olAlias = olMem.GetExchangeUser.Alias
On Error GoTo 0
If olAlias = inAlias Then
GetFullName = olMem.GetExchangeUser.Name
Exit For
Else
GetFullName = "Invalid Alias"
End If
Next
Set olApp = Nothing: Set olNS = Nothing: Set olAdd = Nothing
End Function
欠点は、GAL が非常に大きい場合、時間がかかることです。
最初にリストを配列にダンプしてから、そこから操作できるかどうかを確認します。
または、他の方法を使用してエイリアス経由で名前を取得する別の方法がある場合。
でも今は、まずはここから学んでみてください。
これは関数なので、テキストボックスに入れるには、次のようにするだけです:
TextBox2 = GetFullname(TextBox1)
注:
意図的にすべてのオブジェクトを宣言しました。作業しているオブジェクトのタイプを知る必要があります。また、On Error Resume NextAddressEntry
を使用しました。これは、エラーが発生しないためAlias
です。それが今のところ私が考えることができる最も簡単な回避策です。
要件:
を参照する必要がありますMicrosoft Outlook xx.x Object Library
。
xx.x
マシンにインストールされている Outlook のバージョンによって異なります。