vba 通过 outlook 任务的宏迭代在新对象库中不起作用(12 对 15)
vba macro iteration through outlook tasks not working in new object library (12 vs 15)
编辑:底部的工作解决方案
我的同事将她的办公室更新为 365,其中包含 2013 版本。在 2007 年正常运行的宏现在无法运行。对象库 12 和 15 中可能有一些我不知道的变化。
这是下面的代码。我在线上收到 Application_defined 或对象定义的错误:
Worksheets("ActiveTasks").Cells(rowNo, Column_title).Value = eItem
通过反复试验,我发现 "eItem" 有问题。我尝试定义为 Outlook.TaskItem,删除整体绑定,重新聚焦工作表。在 2007 excel 中一切正常,但在 2013 版本中仍然出现对象错误。
Sub Extract_tasks_SPP()
On Error GoTo ErrHandler
Dim applOutlook As Outlook.Application
Dim nsOutlook As Outlook.Namespace
Dim eFolder As Outlook.folder
Dim eItems As Outlook.Items
Dim eItem As Object
Dim eResItems As Outlook.Items
Dim strCriteria As String
Worksheets("ActiveTasks").Range("A:B").ClearContents
Set applOutlook = New Outlook.Application
Set nsOutlook = applOutlook.GetNamespace("MAPI")
nsOutlook.Logon
Set Recip = nsOutlook.CreateRecipient("InboxName")
Set SharedFolder = nsOutlook.GetSharedDefaultFolder(Recip, olFolderTasks)
Set eFolderSPP = SharedFolder
Set eItemsSPP = eFolderSPP.Items
If eItemsSPP.Count < 1 Then
MsgBox "No Task Items Returned"
Exit Sub
End If
rowNo = 1
Column_title = 1
For Each eItem In eItemsSPP
Worksheets("ActiveTasks").Cells(rowNo, Column_title).Value = eItem ' I get object defined error on this line. I believe it is eItem that is causing issue
rowNo = rowNo + 1
Next
Set applOutlook = Nothing
Set nsOutlook = Nothing
Set eFolderSPP = Nothing
Set eItemsSPP = Nothing
Set eResItemsSPP = Nothing
Exit Sub
ErrHandler:
MsgBox "Opps, something went wrong. Script will exit"
End
End Sub
对可能出现的问题有什么想法吗?
解决方案是为 eItem 设置对象 属性:
Worksheets("ActiveTasks").Cells(rowNo, Column_title).Value = eItem.Subject
解决方案是为 eItem 设置对象 属性:
Worksheets("ActiveTasks").Cells(rowNo, Column_title).Value = eItem.Subject
编辑:底部的工作解决方案
我的同事将她的办公室更新为 365,其中包含 2013 版本。在 2007 年正常运行的宏现在无法运行。对象库 12 和 15 中可能有一些我不知道的变化。
这是下面的代码。我在线上收到 Application_defined 或对象定义的错误:
Worksheets("ActiveTasks").Cells(rowNo, Column_title).Value = eItem
通过反复试验,我发现 "eItem" 有问题。我尝试定义为 Outlook.TaskItem,删除整体绑定,重新聚焦工作表。在 2007 excel 中一切正常,但在 2013 版本中仍然出现对象错误。
Sub Extract_tasks_SPP()
On Error GoTo ErrHandler
Dim applOutlook As Outlook.Application
Dim nsOutlook As Outlook.Namespace
Dim eFolder As Outlook.folder
Dim eItems As Outlook.Items
Dim eItem As Object
Dim eResItems As Outlook.Items
Dim strCriteria As String
Worksheets("ActiveTasks").Range("A:B").ClearContents
Set applOutlook = New Outlook.Application
Set nsOutlook = applOutlook.GetNamespace("MAPI")
nsOutlook.Logon
Set Recip = nsOutlook.CreateRecipient("InboxName")
Set SharedFolder = nsOutlook.GetSharedDefaultFolder(Recip, olFolderTasks)
Set eFolderSPP = SharedFolder
Set eItemsSPP = eFolderSPP.Items
If eItemsSPP.Count < 1 Then
MsgBox "No Task Items Returned"
Exit Sub
End If
rowNo = 1
Column_title = 1
For Each eItem In eItemsSPP
Worksheets("ActiveTasks").Cells(rowNo, Column_title).Value = eItem ' I get object defined error on this line. I believe it is eItem that is causing issue
rowNo = rowNo + 1
Next
Set applOutlook = Nothing
Set nsOutlook = Nothing
Set eFolderSPP = Nothing
Set eItemsSPP = Nothing
Set eResItemsSPP = Nothing
Exit Sub
ErrHandler:
MsgBox "Opps, something went wrong. Script will exit"
End
End Sub
对可能出现的问题有什么想法吗?
解决方案是为 eItem 设置对象 属性:
Worksheets("ActiveTasks").Cells(rowNo, Column_title).Value = eItem.Subject
解决方案是为 eItem 设置对象 属性:
Worksheets("ActiveTasks").Cells(rowNo, Column_title).Value = eItem.Subject