2017-03-02 75 views
0

我的主要問題如何將一個activecellvalue投擲到getexchangeuser對象以獲取該特定用戶的主管?我想下面的代碼,因爲我不知道如何做,但我得到一個錯誤91對象變量未設置。Excel VBA Getexchangeuser.Getexchangeusermanager查詢

Set Usersupervisor = myExchangeuser.GetExchangeUser(ActiveCell.Cells(1, 10)).GetExchangeUserManager.Alias 

這行代碼,雖然作品,如果我需要我自己的上司。

.To = outlookmail.Session.CurrentUser.AddressEntry.GetExchangeUser.GetExchangeUserManager.Alias 

基本上我有沒有在Outlook解析收件人的別名或用戶名。我需要查找特定別名的經理信息並在.To字段中使用。這甚至有可能嗎?大部分指南都不符合我的要求。

Dim outlookapp As Outlook.Application 
Dim outlookmail As Outlook.MailItem 
Dim myusername As String 
Dim myExchangeuser As Outlook.ExchangeUser 
Dim mngname As Outlook.AddressEntry 
Dim mysupervisor As String 

myusername = Environ("Username") 

mysupervisor = CStr(myExchangeuser.GetExchangeUser(ActiveCell.Cells(1, 10)).GetExchangeUserManager.Alias) 


Set outlookapp = New Outlook.Application 

Set outlookmail = outlookapp.CreateItemFromTemplate("C:\Users\" & myusername & "\AppData\Roaming\Microsoft\Templates\x.oft") 

With outlookmail 



'.To = ActiveCell.Cells(1, 10) 
'.To = outlookmail.Session.CurrentUser.AddressEntry.GetExchangeUser.GetExchangeUserManager.Alias 
.To = mysupervisor 

End With 

ActiveCell.Cells(1, 13) = "Yes" 
ActiveCell.Cells(1, 14) = DateTime.Now 
outlookmail.Display 

回答

0

好吧,我做了它的工作。感謝大量的文章,雖然不是確切但可用於獲取語法的格式。謝謝堆棧溢出:

Set olns = GetNamespace("MAPI") 
Set myrecipient = olns.CreateRecipient(PMstring) 
myrecipient.Resolve 
PMentry = myrecipient.AddressEntry.GetExchangeUser.GetExchangeUserManager.Alias 



With outlookmail 

.To = PMentry