如何获得 Outlook.NameSpace.CurrentUser 值?

How to get Outlook.NameSpace.CurrentUser value?

Dim app As Microsoft.Office.Interop.Outlook.Application = GetApplicationObject()
Dim ns As Microsoft.Office.Interop.Outlook._NameSpace = Nothing
Dim inboxFolder As Microsoft.Office.Interop.Outlook.MAPIFolder = Nothing
ns = app.GetNamespace("MAPI")

ns.CurrentUser = Username

我正在尝试获取用户名数据项的 .CurrentUser 值。

我收到这个编译器错误:

Property 'CurrentUser' is 'ReadOnly'

我怎样才能得到它的价值?尝试使用 Get Return.

将代码更改为

Username = ns.CurrentUser.Name

您似乎试图在 Outlook 中设置当前用户,但这是不可能的。 属性 与错误消息状态一样,是只读的。如果要获取用户名,则需要在赋值运算符的右侧有操作数:

CurrentUser property of the Namespace class returns the currently logged-on user as a Recipient object which represents a user or resource in Outlook, generally a mail or mobile message addressee. The Recipient.Name 属性 returns 表示对象显示名称的字符串值。

Dim myNamespace As Outlook.NameSpace 
Dim recipient as Outlook.Recipient
Dim userName as string

myNameSpace = Application.GetNameSpace("MAPI") 
recipient = myNameSpace.CurrentUser 
userName = recipient.Name