简体   繁体   English

运行时错误 462 - 从 Excel 中删除 Outlook 约会

[英]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.

相关问题 运行时错误438:从Excel中删除Outlook约会 - Run-Time Error 438: Deleting Outlook Appointments from Excel Excel 到 Word 宏导致运行时错误 462 - Excel to Word Macro resulting in Run-time error 462 运行时错误“462” - Excel 自动化在第二次代码运行时失败 - Run-time error '462' - Excel automation fails second time code runs 在 VBA 中打开 Excel 文件:运行时错误“462”:远程服务器计算机不存在或不可用 - Opening Excel file in VBA: Run-time error ‘462’: The remote server machine does not exist or is unavialiable Excel到Outlook:.Send返回运行时错误 - Excel to Outlook: .Send returns Run-time Error 运行时错误462使用Excel访问VBA - Run time error 462 Access VBA using Excel 第二次在EXCEL中运行VBA代码时,出现“运行时错误462:远程服务器计算机不存在或不可用”(获取访问表) - “Run-time error 462: The remote server machine does not exist or is unavailable” when running VBA code in EXCEL for a second time (get ACCESS table) Excel Automation错误运行时错误440-自动更正Outlook约会。 - Excel Automation Error Run-time Error 440- Autocorrecting Outlook Appointment .Start 从excel粘贴到powerpoint时VBA中的运行时错误 - Run-time error in VBA on pasting from excel to powerpoint 通过Outlook运行Excel宏:运行时错误'-2147417851(80010105)' - Running Excel macro through Outlook: Run-time error '-2147417851(80010105)'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM