高手们帮看看这个vba怎么修正,谢谢!
这是人家的个代码,是把outlook中的邮件信息提取出来到excel表中,我用的时候报错:用户定义类型未定义.
跟office版本有关系吗?我版本是office2010的,原作者没说要另外定义什么类型啊.原作者文章地址:http://mrvsto.com/2010/03/list-all-mails-of-outlook-to-excel/
要怎么修正呢?谢谢!
Sub showAllEmails()
Dim OLF As Outlook.MAPIFolder'这一行报错:用户定义类型未定义
Dim Emails&, i&, k&
Dim arr
Application.ScreenUpdating = False
Set OLF = GetObject("", "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Emails = OLF.Items.Count
ReDim arr(1 To Emails + 1, 1 To 5)
arr(1, 1) = "Subject"
arr(1, 2) = "ReceivedTime"
arr(1, 3) = "Attachments"
arr(1, 4) = "Read"
arr(1, 5) = "Size"
For i = 1 To Emails
With OLF.Items(i)
arr(i + 1, 1) = .Subject
arr(i + 1, 2) = Format(.ReceivedTime, "yyyy-m-d")
arr(i + 1, 3) = .Attachments.Count
arr(i + 1, 4) = IIf(.UnRead, "False", "True")
arr(i + 1, 5) = .Size
End With
Next
Set OLF = Nothing
ActiveSheet.Range("a1").Resize(UBound(arr), 5) = arr
Columns("A:F").AutoFit
Application.ScreenUpdating = True
MsgBox "OK"
End Sub
[解决办法]
你安装OutLook了吗?
如果安装了,还要在引用中添加一下OutLook的引用才行。
[解决办法]
打开Visual Basic编辑器-》工具-》引用,选择 Microsoft OutLook............(具体名称自己找吧)
[解决办法]
工程->引用:microsoft office11.0 object library
Dim OLF As new Outlook.MAPIFolder
[解决办法]
前面全是对的,找不着那个类。