如何修复对象'_AppointmentItem'的方法'Location'失败错误?

时间:2018-12-07 19:55:00

标签: vba outlook

我阅读了一个打开的约会项目的各个元素,并将其显示在消息框中:

Private Sub MessageAppointmentInfo()    

    Dim objItem As Object
    Dim objApp As Outlook.Application
    Dim mySubject As String
    Dim myLocation As String
    Dim myStartDate As Date

    Set objApp = Application

    Set objItem = objApp.ActiveExplorer.Selection.Item(1)

    With objItem

        mySubject = .Subject
        myLocation = .Location
        myStartDate = .Start

    End With

    MsgBox mySubject & myStartDate & myLocation

End Sub

如果我注释掉myLocation和myStartDate,它将运行。

为什么位置和开始日期与主题不同?

我得到:

  

对象'_AppointmentItem'的方法'Location'失败

当我点击调试时,它会突出显示myLocation = .Location

我对Outlook VBA并不熟悉-我对Access和Excel更加满意。

1 个答案:

答案 0 :(得分:0)

如果您主要是想避免仍然无法使用Location的错误,则在失败的情况下让执行简单地继续执行下一条指令,并提供空白的Location:

 
...

With objItem

    mySubject = .Subject
    myLocation = ""
    On Error Resume Next
    myLocation = .Location
    On Error Goto 0 ' switch off error handling
    myStartDate = .Start

End With

...