大佬教程收集整理的这篇文章主要介绍了使用 Excel VBA 捕获 Outlook 地址,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在 Excel 中有一个自定义 VBA 函数,用于获取关联的 Office 用户的电子邮件地址。它对某些用户任意触发 - 有时有效,有时无效。
我的最终用户并非都使用最新版本的 Excel,但这是唯一导致问题的 VBA 函数。对于受影响的用户,它往往在他们第一次打开文件时更有效,然后在后续打开时变得惰性。
Function Username() As String
Dim ol As Object,olAllUsers As Object,oExchUser As Object,oentry As Object,myitem As Object
Dim User As String
Set ol = CreateObject("outlook.application")
Set olAllUsers = ol.Session.AddressLists.Item("All Users").AddressEntrIEs
User = ol.Session.CurrentUser.name
Set oentry = olAllUsers.Item(User)
Set oExchUser = oentry.GetExchangeUser()
Username = oExchUser.PriMarySmtpaddress
End Function
我尝试了网络上的一些解决方案均无济于事,并尝试强制单元格重新计算,但似乎对于受影响的用户而言,一旦该函数决定不执行任何操作,重新计算就无关紧要。
>可以稍微简化一下代码:
Function UserName() As String
Dim OL As Object,oExchUser As Object,oentry As Object,myitem As Object
Dim User As String
Set OL = CreateObject("outlook.application")
'
' use NameSpace.Logon if required
'
Set oentry = Ol.Session.CurrentUser.AddressEntry
'
' here you can also check whether it is an Exchange account
'
Set oExchUser = oentry.GetExchangeUser()
UserName = oExchUser.PriMarySmtpaddress
End Function
以上是大佬教程为你收集整理的使用 Excel VBA 捕获 Outlook 地址全部内容,希望文章能够帮你解决使用 Excel VBA 捕获 Outlook 地址所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。