1.直接在OUTLOOK里加入一段宏代码。 Sub CreateNewAM() '如何将存储区上的搜索文件夹“昨天邮件”中的邮件数读到EXCLE中 Dim olApp As New Outlook.Application Dim excelApp As Object Dim colStores As Outlook.Stores Dim oStore As Outlook.Store Dim oSearchFolders As Outlook.Folders Dim oFolder As Outlook.Folder On Error Resume Next Set colStores = olApp.Session.Stores olunreadmail = colStores.Item(1).GetSearchFolders("昨天邮件").UnReadItemCount Set excelApp = GetObject(, "excel.Application") excelApp.Worksheets("Sheet1").Activate excelApp.Range("B1").Value = olunreadmail Set excelApp = Nothing End Sub
2.在EXCEL里执行宏代码,同样可以 Sub CreateNewAM() '请在工具-》引用中选中Microsoft Outlook的library Dim olApp As Object 'Dim colStores As Outlook.Stores Dim colStores As Object Dim olUnReadMail As Long On Error Resume Next Set olApp = GetObject(, "Outlook.Application") If Err.Number <> 0 Then Set olApp = CreateObject("Outlook.Application") End If ' On Error Resume Next Set colStores = olApp.Session.Stores olUnReadMail = colStores.Item(1).GetSearchFolders.Item("昨天邮件").UnReadItemCount Worksheets("Sheet1").Activate Range("B1").Value = olUnReadMail Set olApp = Nothing End Sub
[此贴子已经被作者于2007-10-15 2:39:18编辑过] |