我想從Excel VBA(Excel 2010)宏中刪除所有約會,但在olFolder.Items.GetFirst上得到錯誤13(類型不匹配)。我無法解釋爲什麼,因爲它幾周前完美無瑕。Excel 2010 VBA代碼刪除所有Outlook約會
任何人誰可以給我個忙錯誤=
Here's VBA代碼:
Sub DeleteAllAppointments()
Dim olApp As Object
Application.ScreenUpdating = False
Set olApp = CreateObject("Outlook.Application")
Dim olApptItem As Outlook.AppointmentItem
Dim olMeetingItem As Outlook.MeetingItem
Dim olNameSpace As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim olObject As Object
Dim olItems As Items
Dim i As Double
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olFolder = olNameSpace.GetDefaultFolder(olFolderCalendar)
Set olItems = olFolder.Items
Set olApptItem = olFolder.Items.GetFirst
For i = 1 To olItems.Count
If olItems.Count > 1 Then
olApptItem.Delete
Set olApptItem = olFolder.Items.GetNext
Else
Set olApptItem = olFolder.Items.GetLast
olApptItem.Delete
End If
Next
End Sub
假設你有一個對Outlook的引用,只要你像這樣'Outlook.AppointmentItem'的前言就可以使用'AppointmentItem' –
@D_Bester謝謝。 –