【发布时间】:2015-07-14 09:40:13
【问题描述】:
我正在尝试从 Excel 中搜索具有特定主题的 Outlook 电子邮件:
Sub Work_with_Outlook()
Set olApp = CreateObject("Outlook.Application")
Dim olNs As Outlook.Namespace
Dim Fldr As Outlook.MAPIFolder
Dim olMail As Variant
Dim sir() As String
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set myTasks = Fldr.Items
Set olMail = myTasks.Find("[Subject] = ""*desired subject*""")
If Not (olMail Is Nothing) Then
sir = Split(olMail.Body, vbCrLf)
For i = 1 To UBound(sir)
ActiveWorkbook.Sheets("Sheet1").Cells(i, 1).Value = sir(i)
Next i
olMail.Delete
End If
End Sub
我在 Excel 中收到错误提示
用户定义类型未定义
在这一行:
Dim olNs As Outlook.Namespace
【问题讨论】: