0
我正在寻找一种方法将不同的Outlook帐户的信息拉入Excel电子表格。另一个帐户的参考收件箱
下面的代码仅适用于我的个人收件箱:
Sub psinbox()
Dim olNs As Outlook.Namespace
Dim oltaskfolder As Outlook.MAPIFolder
Dim oltask As Outlook.TaskItem
Dim olitems As Outlook.Items
Dim xlapp As Excel.Application
Dim xlWB As Excel.Workbook
Dim x As Long
Dim arrheaders As Variant
Set olNs = GetNamespace("MAPI")
Set oltaskfolder = olNs.GetDefaultFolder(olFolderInbox)
Set olitems = oltaskfolder.Items
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = True
Set xlWB = xlapp.Workbooks.Add
x = 2
arrheaders = Array("Date Created", "Date Recieved", "Subject", "Sender",
"Senders Email", "CC", "Sender's Email Type", "MSG Size", "Unread?")
On Error Resume Next
xlWB.Worksheets(1).Range("A1").Resize(1, UBound(arrheaders)).Value = ""
Do
With xlWB.Worksheets(1)
If Not (olitems(x).Subject = "" And olitems(x).CreationTime = "") Then
.Range("A1").Resize(1, UBound(arrheaders) + 1) = arrheaders
.Cells(x, 1).Value = olitems(x).CreationTime
.Cells(x, 2).Value = olitems(x).recievedtime
.Cells(x, 3).Value = olitems(x).Subject
.Cells(x, 4).Value = olitems(x).SenderName
.Cells(x, 6).Value = olitems(x).CC
.Cells(x, 7).Value = olitems(x).SenderEmailType ' this is either internal or external server
.Cells(x, 8).Value = Format((olitems(x).Size/1024)/1024, "#,##0.00") & " MB"
.Cells(x, 9).Value = olitems(x).UnRead
x = x + 1
End If
End With
Loop Until x >= olitems.Count + 1
Set olNs = Nothing
Set oltaskfolder = Nothing
Set olitems = Nothing
Set xlapp = Nothing
Set xlWB = Nothing
End Sub
我想记录接收到的电子邮件有多少未读。
最近我发现在这里Count Read and Unread Emails date wise for shared mailbox,其中提到将需要设置c = b.Folders(“共享邮箱的名称”),但是这似乎是针对同一邮件帐户内的不同文件夹。我所追求的是访问两个不同的帐户,哪些Outlook可以访问?
编辑:
尝试过氡的例子,我有以下的问题。
If objOwner.Resolved Then
Set oltaskfolder = olNs.GetSharedDefaultFolder(objOwner,
olFolderInbox).Folders("admin")
Set olitems = oltaskfolder.Items
End If
我曾尝试使用共享的收件箱,电子邮件地址和电子邮件帐户名的用户名,但都带来了以下错误。
如果您的个人资料中没有邮箱https://stackoverflow.com/questions/27851850/vba-outlook-selecting-a-subfolder-in-the-sharedmailbox-using-getshareddefaultfol否则这是另一个版本您发现的问题https://stackoverflow.com/questions/9076634/get-reference-to-additional-inbox – niton
可能重复的[VBA Outlook选择使用GetSharedDefaultFolder在SharedMailbox中的子文件夹](https://stackoverflow.com/questions/27851850/vba-outlook-selecting-a-sub-folder-in-the-sharedmailbox-using-getshareddefaultfol) – niton
以上是指子文件夹,而不是单独的邮件帐户。不过,我会尝试第一个建议中的链接http://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/ – Kyoujin