【发布时间】:2014-11-03 00:02:15
【问题描述】:
所以我有一个程序可以让用户选择一个 Outlook 文件夹以导入到表中。然后可以从组合框中选择它并传输到表单中以供使用。
但是,我返回的值之一有问题。 SenderEmailAddress 实际上并没有给我一个电子邮件地址,例如这是我保存在我的表中的地址。
出于隐私考虑,我删除了姓名。
/O=COMPANY/OU=MAIL12/CN=RECIPIENTS/CN=FIRSTNAME.LASTNAME
当然,如果我想将此值传递回 Outlook 以回复电子邮件,我不能使用它。
有人可以帮帮我吗?
Public Sub LoadEmails()
On Error Resume Next
'Outlook wasn't running, start it from code
If Started = False Then
Set olApp = New Outlook.Application '("Outlook.Application")
Started = True
End If
Set myNamespace = olApp.GetNamespace("MAPI")
Set objFolder = myNamespace.PickFolder
' if outlook is closed, it will display this error
If Err <> 0 Then
MsgBox "Outlook was closed. Please log out and log back in."
Started = False
Exit Sub
End If
'Exit if no folder picked.
If (objFolder Is Nothing) Then
MsgBox "No Folder Selected"
Started = False
Exit Sub
End If
Dim adoRS As Recordset
Dim intCounter As Integer
Set adoRS = CurrentDb.OpenRecordset("TBL_UserInbox") 'Open table Inbox
'Cycle through selected folder.
For intCounter = objFolder.Items.Count To 1 Step -1
With objFolder.Items(intCounter)
'Copy property value to corresponding fields
If .Class = olMail Then
adoRS.AddNew
adoRS("Subject") = .Subject
adoRS("TimeReceived") = .ReceivedTime
adoRS("Body") = .Body
adoRS("FromName") = .SenderEmailAddress '<<< Issue
adoRS("ToName") = .To
adoRS.Update
End If
End With
Next
MsgBox "Completed"
Started = False
End Sub
【问题讨论】:
-
非常感谢奥利维尔 :)
-
我刚刚实施了修复并且它有效!这篇文章对我很有帮助,谢谢!
标签: vba email ms-access outlook