Vba Outlook宏中的SenderName为空
我想从Vba Outlook宏中的SenderName为空,vba,email,outlook,Vba,Email,Outlook,我想从MailItem对象中获取SenderName和to属性,但它们是空白的 我可以看到有SentOn,Subject和其他属性不是空的。 有人知道为什么这两个是空白的吗 这是我的密码: Sub TestMacro() Dim myOlApp As New Outlook.Application Dim myOlexp As Outlook.Explorer On Error Resume Next Set myOlExp = myOlApp.ActiveExplorer Set myOl
MailItem
对象中获取SenderName
和to
属性,但它们是空白的
我可以看到有SentOn
,Subject
和其他属性不是空的。
有人知道为什么这两个是空白的吗
这是我的密码:
Sub TestMacro()
Dim myOlApp As New Outlook.Application
Dim myOlexp As Outlook.Explorer
On Error Resume Next
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
For Each myItem In myOlSel
strRawSubj = myItem.Subject
strSender = myItem.SenderName 'blank
strLongTo = myItem.To 'blank
Next
End Sub
编辑:
如果我以管理员身份运行Outlook,则此选项有效。
是否可以在不必以管理员身份运行Outlook的情况下获取这些值?请尝试以下操作
在常规模块上使用代码
请试试这个
Sub TestMacro()
Dim myOlexp As Outlook.Explorer
Dim myOlSel As Selection
' On Error Resume Next ' do not use during development ... hides errors
Set myOlexp = Application.ActiveExplorer ' "Application" object already exists
Set myOlSel = myOlexp.Selection
For Each myItem In myOlSel
Debug.Print Len(myItem.Subject) ' print the length of each string
Debug.Print Len(myItem.SenderName) ' maybe the strings are being obfuscated somehow
Debug.Print Len(myItem.To)
Next
Set myOlSel = Nothing
Set myOlexp = Nothing
End Sub
代码没有问题,我可以获取所选项目的
到
和发件人姓名
,这些项目为空的原因是什么?建议您重新创建模块或在的此会话
中插入此宏outlook@AmbrishPathak在我把代码放进数据库后,它仍然是空的“ThisOutlookSession”0m3r已经提供了一个有效的解决方案,但还是要感谢您。那么,您的代码是否因为未声明mailitem对象而失败?
Sub TestMacro()
Dim myOlexp As Outlook.Explorer
Dim myOlSel As Selection
' On Error Resume Next ' do not use during development ... hides errors
Set myOlexp = Application.ActiveExplorer ' "Application" object already exists
Set myOlSel = myOlexp.Selection
For Each myItem In myOlSel
Debug.Print Len(myItem.Subject) ' print the length of each string
Debug.Print Len(myItem.SenderName) ' maybe the strings are being obfuscated somehow
Debug.Print Len(myItem.To)
Next
Set myOlSel = Nothing
Set myOlexp = Nothing
End Sub