【问题标题】:Application -defined or object - defined error referring to Excel Cells in Outlook VBA引用 Outlook VBA 中的 Excel 单元格的应用程序定义或对象定义错误
【发布时间】:2018-03-07 05:53:27
【问题描述】:

以下是我编写的用于自动发送会议邀请的代码。

代码从工作表中的单元格中挑选内容:Final_List。

当我尝试从 Excel 获取收件人地址时,我已突出显示出错的地方

应用程序定义或对象定义错误。

Dim outlookApp As Outlook.Application
Dim outlookmeet As AppointmentItem
Dim myRequiredAttendee As Recipient

Dim sh As Worksheet
Dim RowCount As Long

RowCount = 2
'row 1 has headers

With Worksheets("Final_List")

    Do While IsEmpty(Cells(RowCount, 1).Value) = False

        Set outlookApp = CreateObject("Outlook.Application")
        Set outlookmeet = outlookApp.CreateItem(olAppointmentItem)
        With outlookmeet

            .MeetingStatus = olMeeting

            .Subject = Cells(RowCount, 1).Value & " - " & Cells(RowCount, 2).Value
            .Location = Cells(RowCount, 3).Value
            .Start = Cells(RowCount, 5).Value
            .Duration = Cells(RowCount, 7).Value

            'getting errors on this line                     
            .Recipients.Add (Cells(RowCount, 6).Value)

            .Recipients.ResolveAll

            .Body = Cells(RowCount, 4).Value
            .Send
        End With

        RowCount = RowCount + 1

    Loop
End With

Set outlookmeet = Nothing
Set outlookApp = Nothing
MsgBox "All invites sent!"

【问题讨论】:

  • 您有两个嵌套的With 语句,这意味着内部With 语句中的所有单元格地址都在当前活动的工作表上,可能是也可能不是“Final_List”。
  • @Variatus:我可以激活“Final_List”表。但我无法在邀请中添加收件人?对此有什么帮助吗?
  • AppointmentItem 对象没有Recipient 属性。 msdn.microsoft.com/en-us/library/office/…
  • @variatus:你还能推荐其他方法吗?
  • 问题已解决:

标签: excel outlook vba


【解决方案1】:

AppointmentItem 对象没有 Recipient 属性。 Compare MSDN library

【讨论】:

    【解决方案2】:

    我得到了这个解决方案:

    Sub ScheduleMeeting()
    
        Dim outlookApp As Outlook.Application
        Dim outlookmeet As Outlook.AppointmentItem
    
        Dim RowCount As Long
        Dim Name1 As Variant
    
        RowCount = 2
        'row 1 has headers
        Worksheets("MeetingInvite").Activate
    
        With Worksheets("MeetingInvite")
    
            Do While IsEmpty(Cells(RowCount, 1).Value) = False
    
                Set outlookApp = CreateObject("Outlook.Application")
                Set outlookmeet = outlookApp.CreateItem(olAppointmentItem)
    
                With outlookmeet
    
                    .MeetingStatus = olMeeting
                    .Subject = Cells(RowCount, 1).Value 
                    .Location = Cells(RowCount, 2).Value
                    .Start = Cells(RowCount, 4).Value
                    .Duration = Cells(RowCount, 6).Value
    
                    .RequiredAttendees = Cells(RowCount, 5).Value
    
                    .Body = Cells(RowCount, 3).Value
    
                    .Display
    
                End With
    
                RowCount = RowCount + 1
    
            Loop
        End With
    
        Set outlookmeet = Nothing
        Set outlookApp = Nothing
        'MsgBox "All invites sent!"
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-25
      • 1970-01-01
      • 2020-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多