我想从SenderName
对象获取To
和MailItem
属性,但它们是空白的。
我可以看到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的情况下获取这些值?
答案 0 :(得分:1)
请尝试以下操作...
使用常规模块上的代码
Option Explicit
Public Sub Example()
Dim olMsg As mailitem
Set olMsg = ActiveExplorer.Selection.Item(1)
'// All print on Immediate Window
Debug.Print olMsg.SenderName
Debug.Print olMsg.sender
Debug.Print olMsg.SenderEmailAddress
Debug.Print olMsg.Categories
Debug.Print olMsg.subject
Debug.Print olMsg.To
Debug.Print olMsg.CC
Debug.Print olMsg.ReceivedByName
Debug.Print olMsg.SenderEmailType
End Sub
答案 1 :(得分:0)
请试试这个
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