2017-09-26 2 views
2

Voici le code que j'ai écrit pour automatiser l'envoi d'invitations à des réunions.Erreur définie par l'application ou définie par l'objet faisant référence à Excel Cells dans Outlook VBA

Le code sélectionne le contenu des cellules de la feuille: Final_List.

J'ai souligné où je reçois une erreur lorsque je tente d'obtenir l'adresse du destinataire à partir d'Excel

application -defined ou objet - erreur défini.

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!" 
+0

Vous avez deux déclarations 'With' imbriquées, ce qui signifie toutes les adresses de cellule dans la déclaration' With' intérieure sont sur la feuille active, qui peut ou non être "Liste finale". – Variatus

+0

@Variatus: Je peux activer la feuille "Final_List". Mais je ne suis pas en mesure d'ajouter des destinataires dans l'invitation? Toute aide pour ce point? –

+0

L'objet AppointmentItem n'a pas de propriété 'Recipient'. https://msdn.microsoft.com/en-us/library/office/aa210899(v=office.11).aspx – Variatus

Répondre

0

je suis arrivé cette solution:

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