【问题标题】:Excel VBA that works like scheduling assistant of OutlookExcel VBA,类似于 Outlook 的调度助手
【发布时间】: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 时间

标签: excel vba outlook


【解决方案1】:

FreeBusy 方法由 Recipient 对象实现。您可以在 Recipients(注意复数“s”)对象上调用该方法。遍历所有收件人并在每个收件人上调用 FreeBusy。

或者使用 Recipients.Add 返回的 Recipient 对象

看起来你传递了多个用“;”分隔的收件人调用 Recipients.Add。您必须为每个收件人调用 Recipients.Add。或者您可以改为设置 To 属性(它允许多个收件人用“;”分隔)。

【讨论】:

  • 我不是很擅长 excel vba,如果可以的话,你能发一个示例代码来解释一下
  • 哪一部分?添加多个收件人?还是打电话给 FreeBusy?
  • 两者兼得。我有点想出如何打电话给多个收件人,但我最终是单独做的。为闲。如果可能的话,我想为每个收件人匹配 Freebusy。
  • 无法在 Outlook 对象模型中的单个呼叫中检索多个收件人的忙/闲。您必须一次只接收一个收件人。
  • 那我该怎么做呢?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-10
  • 2014-03-08
  • 1970-01-01
  • 1970-01-01
  • 2017-10-11
  • 2011-07-02
  • 1970-01-01
相关资源
最近更新 更多