【问题标题】:Why would I get an Invalid or unqualified reference part way through an AppointItem?为什么我会通过 ApppointItem 部分获得无效或不合格的参考?
【发布时间】:2021-01-30 18:53:14
【问题描述】:

代码停止运行并突出显示 .Body = "" 并说它是无效或不合格的 参考。非常感谢任何见解。

注意,以Appt_开头的变量都是在另一个模块中定义的全局变量。

Sub RegisterAppointmentList(CName As String)

' adds a list of appontments to the Calendar in Outlook
Dim olApp As Outlook.Application
Dim olAppItem As Outlook.AppointmentItem

Set olAppItem = Application.CreateItem(olAppointmentItem)

On Error Resume Next

Set olApp = GetObject("", "Outlook.Application")
On Error GoTo 0

If olApp Is Nothing Then
    On Error Resume Next
    Set olApp = CreateObject("Outlook.Application")
    On Error GoTo 0
    If olApp Is Nothing Then
        MsgBox "Outlook is not available!"
        Exit Sub
    End If
End If


olAppItem _
    .Location = ""
    .Body = ""
    .Start = Nothing
    .End = Nothing
    .ReminderSet = True
    .ReminderMinutesBeforeStart = 15
    .BusyStatus = olFree
    .RequiredAttendees = "jerry@1sba.com"
     On Error Resume Next
    .Start = Appt_STime
    .End = Appt_ETime
    .Subject = CName & "," & Appt_Subject
    .Location = Appt_Location
    .Body = Appt_Description
    .ReminderSet = True
    .BusyStatus = olBusy
     On Error GoTo 0
    .Save ' saves the new appointment to the default folder

Set olAppItem = Nothing
Set olApp = Nothing
MsgBox "Done !"
End Sub

【问题讨论】:

  • 您缺少with 和end with 声明。

标签: excel vba appointment


【解决方案1】:

如果您想更改多个属性,最好的方法是使用“With”:

With olAppItem
    .Location = ""
    .Body = ""
    .Start = Nothing
    .End = Nothing
    .ReminderSet = True
    .ReminderMinutesBeforeStart = 15
    .BusyStatus = olFree
    .RequiredAttendees = "jerry@1sba.com"
     On Error Resume Next
    .Start = Appt_STime
    .End = Appt_ETime
    .Subject = CName & "," & Appt_Subject
    .Location = Appt_Location
    .Body = Appt_Description
    .ReminderSet = True
    .BusyStatus = olBusy
     On Error GoTo 0
    .Save ' saves the new appointment to the default folder
End With  

【讨论】:

  • 这很有帮助。现在它说“Set olAppItem = Application.CreateItem(olAppointmentItem)”不支持这个属性或方法。它看起来就像网络上的多个代码示例。有什么想法或者我应该发布另一个问题吗?
  • 我想(因为有一个“excel”标签)你正试图从 Excel VBA 运行这段代码,对吗? Application.CreateItem 是 Outlook (docs.microsoft.com/en-us/office/vba/api/…) 上可用的方法,但是当您从 Excel 运行它时,Application 指的是 Excel。也许您应该引用 Outlook 应用程序对象 olApp (Set olAppItem = olApp.CreateItem(olAppointmentItem)),或者尝试在 Outlook VBA 中运行示例。
猜你喜欢
  • 2012-03-17
  • 2017-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多