我试图用VBA迭代某人的前景预约。我相信下面的片段应该做我需要的,然而,行for each appm in cal.items
会弹出一个消息框,上面写着
Laufzeitfehler' -140492795(f7a04405)':
Automatisierungsfehler
在英语中,这可能是运行时错误....自动化错误。
为什么我会收到此错误?
option explicit
sub abcdef()
dim ol as outlook.application
dim ns as outlook.namespace
dim rcpt as outlook.recipient
dim cal as outlook.folder
dim appm as outlook.appointmentItem
set ol = new outlook.application
set ns = ol.GetNamespace("MAPI")
set rcpt = ns.createRecipient("Deere John")
rcpt.resolve
if not rcpt.resolved then
msgBox("Could not resolve recipient")
return
end if
set cal = ns.getSharedDefaultFolder(rcpt, olFolderCalendar)
if cal is nothing then
msgBox ("No Calender!")
return
end if
for each appm in cal.items
' Error occurs in previous line
next appm
end sub
答案 0 :(得分:0)
在这里找到一些代码:http://www.slipstick.com/developer/copy-new-appointments-to-another-calendar-using-vba/这将改变你dim appm
的方式......而不是outlook.appointmentItem
它只是appointmentItem
。所以Dim appm as appoointmentItem
修改:当您使用Set newCalFolder = GetFolderPath("display name in folder list\Calendar\Test")
cal
来定义getSharedDefaultFolder
变量
答案 1 :(得分:0)
即使您可以手动添加" Deere John"在您的日历列表中,日历权限可能不适用于VBA。
尝试此操作以查看Outlook是否显示"无法显示该文件夹。 Microsoft Outlook无法访问指定的文件夹位置。"
Sub abcdef_CalDisplay()
Dim ol As Outlook.Application
Dim ns As Outlook.Namespace
Dim rcpt As Outlook.Recipient
Dim cal As Outlook.folder
Dim appm As Outlook.AppointmentItem
Set ol = New Outlook.Application
Set ns = ol.GetNamespace("MAPI")
Set rcpt = ns.CreateRecipient("Deere John")
rcpt.Resolve
If Not rcpt.Resolved Then
MsgBox ("Could not resolve recipient")
Return
Else ' <----
Set cal = ns.GetSharedDefaultFolder(rcpt, olFolderCalendar)
cal.Display ' <---
End If
End Sub