【发布时间】:2020-06-28 09:13:41
【问题描述】:
在创建 VBA 代码方面非常陌生,不能单独编写。是否可以创建一个像 Outlook 的日程安排助手一样工作的 VBA 代码?我希望它像调度助手一样工作。我尝试了freebusy,但它显示“对象不支持此方法”
我在这部分,我可以使用 excel 信息发送详细信息。
Option Explicit
Sub AddAppointments()
Dim myoutlook As Object ' Outlook.Application
Dim r As Long
Dim myapt As Object ' Outlook.AppointmentItem
Dim time As String
' late bound constants
Const olAppointmentItem = 1
Const olBusy = 2
Const olMeeting = 1
' Create the Outlook session
Set myoutlook = CreateObject("Outlook.Application")
' Start at row 2
r = 2
Do Until Trim$(Cells(r, 1).Value) = ""
' Create the AppointmentItem
Set myapt = myoutlook.CreateItem(olAppointmentItem)
' Set the appointment properties
With myapt
.Subject = Cells(2, 1).Value
.Location = Cells(3, 1).Value
.Start = Cells(4, 1).Value
time = .Start
.Duration = Cells(5, 1).Value
.Recipients.Add Cells(8, 1).Value & ";" & _
Cells(8, 2).Value & ";" & _
Cells(8, 3).Value & ";" & _
Cells(8, 4).Value & ";" & _
Cells(8, 5).Value & ";" & _
Cells(8, 6).Value & ";" & _
Cells(8, 7).Value & ";" & _
Cells(8, 8).Value & ";" & _
Cells(8, 9).Value & ";" & _
Cells(8, 10).Value
.MeetingStatus = olMeeting
' not necessary if recipients are email addresses
myapt.Recipients.ResolveAll
'myapt.Recipients.FreeBusy = "(#8/8/2015#, 60, False)"
' .AllDayEvent = Cells(9, 1).Value
' If Busy Status is not specified, default to 2 (Busy)
If Len(Trim$(Cells(5, 1).Value)) = 0 Then
.BusyStatus = olBusy
Else
.BusyStatus = Cells(5, 1).Value
End If
If Cells(6, 1).Value > 0 Then
.ReminderSet = True
.ReminderMinutesBeforeStart = Cells(6, 1).Value
Else
.ReminderSet = False
End If
.Body = Cells(7, 1).Value
.Save
r = r + 1
.Display
End With
Loop
End Sub
【问题讨论】:
-
那么哪一行会抛出该错误?
-
'myapt.Recipients.FreeBusy = "(#8/8/2015#, 60, False)" 这行抛出错误。似乎它需要一些调整,并且它没有得到多个收件人的 FreeBusy 时间