2017-03-02 79 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