Een familie van Microsoft-spreadsheetsoftware met hulpmiddelen voor het analyseren, in kaart brengen en communiceren van gegevens.
I got it to work.
Essential is that in Excel VBA editor at Tools -> References -> Microsoft Outlook 16.0 Object Library is ticked!
Sub StuurKaartjes()
Dim ol As Outlook.Application
Dim mi As Outlook.MailItem
Dim ToName As String
Dim DocPath As String
Dim DocName As String
Dim x As Long
Dim LR As Long
Application.ScreenUpdating = False
LR = Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To LR 'regel 1 bevat kolomkoppen
If Range("M" & x).Value <> "Yes" Then
ToName = Range("D" & x).Value 'mailadressen
DocPath = Range("K" & x).Value 'pad naar documenten
DocName = Range("L" & x).Value 'documentnaam
Set ol = New Outlook.Application
Set mi = ol.CreateItem(olMailItem)
mi.Display
mi.Subject = "Test"
mi.To = ToName
mi.Body = "Testing 123"
mi.Attachments.Add DocPath & "\" & DocName & ".pdf"
mi.SendUsingAccount = ol.Session.accounts("******@test.nl")
mi.Send
Range("M" & x).Value = "Yes"
Else
End If
Next x
Set ol = Nothing
Set mi = Nothing
Application.ScreenUpdating = True
End Sub
To be sure there are different accounts present, you can check it by running this code in VBA editor.
Option Explicit
Sub ListAccountNames()
Dim ol As Outlook.Application
Dim ac As Outlook.account
Set ol = New Outlook.Application
For Each ac In ol.Session.accounts
Debug.Print ac.DisplayName
Next ac
End Sub
After running it in the pane "Direct" the results are shown.