我正在嘗試使用VBA迭代某人的Outlook約會。我相信下面的代碼片段應該做什麼,我需要,但for each appm in cal.items
彈出一個小消息框,指出無法使用VBA迭代其他人的約會
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
是因爲你有'Dim appm As Outlook.AppointmentItem',並且你正在使用'for每個apt.m文件中的? 您是否已啓用Option Explicit或強制變量聲明?如果是這樣,那麼你會看到一個錯誤,看appm <> aptm – 2014-11-21 14:14:45
好點,但它不是真正的原因。我已經更改了變量名稱並添加了「顯式選項」,並且錯誤仍然存在。 – 2014-11-21 14:24:41