在帐户/文件夹中创build邮件的Excel列表/日志的macros

这是我的macros。 我认为我可以理解代码,然后编辑它,并得到我想要的东西第一:macros没有任何进展根本:“编译错误:userdefined typenot defined”我甚至不知道这是什么东西:)(我使用macros现在在一个新的和emty工作簿)

Sub ListAllItemsInInbox() Dim OLF As Outlook.MAPIFolder, CurrUser As String Dim EmailItemCount As Integer, i As Integer, EmailCount As Integer Application.ScreenUpdating = False Workbooks.Add ' create a new workbook ' add headings Cells(1, 1).Formula = "Subject" Cells(1, 2).Formula = "Recieved" Cells(1, 3).Formula = "Attachments" Cells(1, 4).Formula = "Read" With Range("A1:D1").Font .Bold = True .Size = 14 End With Application.Calculation = xlCalculationManual Set OLF = GetObject("", _ "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox) EmailItemCount = OLF.Items.Count i = 0: EmailCount = 0 ' read e-mail information While i < EmailItemCount i = i + 1 If i Mod 50 = 0 Then Application.StatusBar = "Reading e-mail messages " & _ Format(i / EmailItemCount, "0%") & "..." With OLF.Items(i) EmailCount = EmailCount + 1 Cells(EmailCount + 1, 1).Formula = .Subject Cells(EmailCount + 1, 2).Formula = Format(.ReceivedTime, "dd.mm.yyyy hh:mm") Cells(EmailCount + 1, 3).Formula = .Attachments.Count Cells(EmailCount + 1, 4).Formula = Not .UnRead End With Wend Application.Calculation = xlCalculationAutomatic Set OLF = Nothing Columns("A:D").AutoFit Range("A2").Select ActiveWindow.FreezePanes = True ActiveWorkbook.Saved = True Application.StatusBar = False End Sub 

正如我已经在上面的注释中提到的MSDN文章所述,您可以通过MS Excel中的Late Binding (LB)Early Binding (EB)与MS Outlook进行Late Binding (LB)

现在什么是LB和EB? 为此,我会再次引导您到另一个MSDN链接。

当您使用EB时,您必须从Tools ~~> References设置对相关应用程序的Tools ~~> References ,并将您的引用设置为相关的Outlook对象库。 例如

在这里输入图像说明

在Layman术语中,Excel现在可以理解OutlookMAPIFolder是什么。 同样, olFolderInbox是一个值为6的Outlook常量。 因此,如果您要设置参考,您的原始代码将无误地工作。

当你使用LB时,你不要设置参考。 你声明你的对象为Objects 。 运行期间由Excel分析。 关于这方面的更多信息已经在上面的链接中介绍过了。 另外,因为我们是晚期绑定,我们必须显式使用6而不是olFolderInbox因为这是它的价值。

希望这会使你走上正轨。 如果有任何问题,请提问。