[英]Run-Time Error 462 - Delete Outlook Appointments from Excel
The code below deletes appointments in a subfolder of the Outlook default calendar.下面的代码删除 Outlook 默认日历的子文件夹中的约会。 I have commented out the line giving the run-time error 462: "The remote server machine does not exist or is unavailable".
我已注释掉给出运行时错误 462 的行:“远程服务器计算机不存在或不可用”。
Is there a change I could make to this code to solve this error?我可以对此代码进行更改以解决此错误吗? Thanks for any guidance.
感谢您的任何指导。
Public Sub DeleteAppt()
Dim olApp As Object 'Outlook.Application
Dim olNS As Object 'Outlook.Namespace
Dim olAptItemFolder As Object 'Outlook.Folder
Dim olAptItem As Object 'Outlook.AppointmentItem
Dim i As Long
Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.Session
Set olAptItemFolder = olNS.GetDefaultFolder(olFolderCalendar).Folders("TestCal")
''''For i = olAptItemFolder.Count To 1 Step -1
Set olAptItem = olAptItemFolder.Items(i)
If olAptItem.Subject Like "***" Then
olAptItem.Delete
End If
Next i
Set olAptItem = Nothing
Set olAptItemFolder = Nothing
Set olApp = Nothing
End Sub
olAptItemFolder
has no Count
property. olAptItemFolder
没有Count
属性。 olAptItemFolder.Items
does. olAptItemFolder.Items
确实如此。 Apart from the issues others noted in comments above, try除了上面评论中提到的其他问题外,请尝试
For i = olAptItemFolder.Items.Count To 1 Step -1
Edited to add: if you are not setting a reference to something's object lirary, you can't use its enums unless you fully qualify each use.编辑添加:如果您没有设置对某物的对象库的引用,则除非您完全限定每次使用,否则不能使用其枚举。 It's generally simpler, easier and quicker to find out the numerical value of the enum and use that instead.
找出枚举的数值并使用它通常更简单、更容易、更快。 Then add a comment on the end of the line to remind yoursef, six months from now, that
'9 = olFolderCalendar
然后在行尾添加注释以提醒你自己,六个月后,
'9 = olFolderCalendar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.