我有一个工作不一致的宏,它无法运行而不会在某个阶段发生错误。它在几天内没有任何问题,但随后就没有了,似乎没有原因。我什么也不改变,不做任何不同的事情,我对VBA/宏的多变感到好奇,现在已经处理了几个星期了。如果程序没有按预期运行,则会产生错误。
错误:对象不支持此属性或方法
——尽管在插入。
时会生成标题选项Sub SnoozedReminders()
Dim oReminder As Reminder
Dim oReminders As Outlook.Reminders
Dim RemItems As String
Set oReminders = Outlook.Reminders
For Each oReminder In oReminders
If (oReminder.OriginalReminderDate <> oReminder.NextReminderDate)
Then
RemItems = RemItems & oReminder.Caption & vbCrLf & _
"Original Reminder time: " & oReminder.OriginalReminderDate & vbCrLf
& _
"Snoozed to: " & oReminder.NextReminderDate & vbCrLf _
& vbCrLf
End If
Next oReminder
Set oMail = Application.CreateItem(olMailItem)
oMail.Subject = "Generated on " & Now
oMail.Body = RemItems
oMail.Display
End Sub
在代码中,您试图为对象设置类型:
Set oReminders = Outlook.Reminders
相反,您需要使用以下代码,使用Outlook应用程序类的提醒属性:
Set oReminders = Application.Reminders
例如,下面的代码获取Reminders
集合并显示集合中所有提醒的标题。如果当前没有可用的提醒,则向用户显示一条消息。
Sub ViewReminderInfo()
'Lists reminder caption information
Dim objRem As Outlook.Reminder
Dim objRems As Outlook.Reminders
Dim strTitle As String
Dim strReport As String
Set objRems = Application.Reminders
strTitle = "Current Reminders:"
strReport = ""
'If there are reminders, display message
If Application.Reminders.Count <> 0 Then
For Each objRem In objRems
'Add information to string
strReport = strReport & objRem.Caption & vbCr
Next objRem
'Display report in dialog
MsgBox strTitle & vbCr & vbCr & strReport
Else
MsgBox "There are no reminders in the collection."
End If
End Sub