在 Outlook 2010 中延迟会议邀请-vba

在 Outlook 2010 中延迟会议邀请-vba

我正在尝试编写代码来安排会议邀请并延迟在以后的日期/时间自动发送给参与者,即延迟发送会议邀请

下面是代码,但当我想要 30 分钟后发送邀请时,它出现了错误。

错误行:

应用程序.等待(现在 + 时间值(“06:30:00”))

非常感谢您的帮助。非常感谢

Sub Book_meeting_room()


Dim olApp As Outlook.Application
Dim olApt As AppointmentItem

Set olApp = Outlook.Application                 'Creating Outlook Session
Set olApt = olApp.CreateItem(olAppointmentItem) 'Creating an Appointment

With olApt

.MeetingStatus = olMeeting                  'olAppointmentItem with Meeting status olMeeting
                                            'becomes a OL Meeting Item.
.Subject = "Room 1"                         'Subject
.Start = #11/20/2017 8:30:00 AM#            'Enter Date + Time here.
.Duration = 240                             'In Minutes
.Location = "Office"                        'Location of the meeting.
.Recipients.Add ("Margaret")                'Recipient Name, Alias, or any other Attribute.
.BusyStatus = olFree
.ReminderSet = True
.ReminderMinutesBeforeStart = 20

End With

Application.Wait (Now + TimeValue("06:30:00"))          'defer 06hrs and 30mins.
olApt.Send                             'Sending Mail.
Set olApt = Nothing

MsgBox "Invite Sent", vbInformation

End Sub

答案1

Application.Wait不适用于 Outlook,您可以使用Doevent计时器功能,也可以使用Sleep功能

使用Doevent是最好的选择,因为它允许您在启动宏后继续工作,如果过度使用它就会出现问题:

Public Sub Pause(Seconds As Single)
Dim TimeEnd As Single
TimeEnd = Timer + Seconds
While Timer < TimeEnd
    DoEvents
Wend
End Sub 

使用 sleep 时,您需要声明该函数,并且在发送消息之前,它将不允许您继续工作。您可以使用以下命令声明它:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

您的代码如下所示(您还可以注意将要解决的其他问题以.Display使程序正常运行)

Sub Book_meeting_room()

Dim olApp As Outlook.Application
Dim olApt As AppointmentItem

Set olApp = Outlook.Application                 'Creating Outlook Session
Set olApt = olApp.CreateItem(olAppointmentItem) 'Creating an Appointment

With olApt

.MeetingStatus = olMeeting                  'olAppointmentItem with Meeting status olMeeting
                                            'becomes a OL Meeting Item.
.Subject = "Room 1"                         'Subject
.Start = #11/20/2017 8:30:00 AM#            'Enter Date + Time here.
.Duration = 240                             'In Minutes
.Location = "Office"                        'Location of the meeting.
.Recipients.Add ("Margaret")                'Recipient Name, Alias, or any other Attribute.
.BusyStatus = olFree
.ReminderSet = True
.ReminderMinutesBeforeStart = 20
.Display

End With

Pause (23400) 'defer 06hrs and 30mins.
'Sleep (23400) 'also defer 06hrs and 30mins eventually

olApt.Send                             'Sending Mail.
Set olApt = Nothing

MsgBox "Invite Sent", vbInformation

End Sub

相关内容