Dit is mijn huidige code:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| Sub SendMail(what_address As String, subject_line As String, mail_body As String)
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")
Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = what_address
olMail.Subject = subject_line
olMail.BodyFormat = olFormatHTML
olMail.HTMLBody = mail_body
olMail.Send
End Sub
-------------------------------------------------------------------------------------------------------------------------
Sub SendMassEmail()
row_number = 1
Do
DoEvents
row_number = row_number + 1
Dim mail_body_message As String
Dim full_name As String
mail_body_message = Blad3.Range("A2")
full_name = Blad2.Range("M" & row_number) & " " & Blad2.Range("O" & row_number) & " " & Blad2.Range("P" & row_number)
mail_body_message = Replace(mail_body_message, "replace_name", full_name)
Call SendMail(Blad2.Range("Q" & row_number), "U heeft toegang tot de website van *** ", mail_body_message)
Loop Until row_number = 7
End Sub |
Of deze
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
| Sub OutlookMail_1(what_address As String, subject_line As String, mail_body As String)
Dim applOL As Outlook.Application
Dim miOL As Outlook.MailItem
Dim recptOL As Outlook.Recipient
Dim ws As Worksheet
'set worksheet:
Set ws = ThisWorkbook.Sheets("Blad2")
'Create a new instance of the Outlook application. Set the Application object as follows:
Set applOL = New Outlook.Application
'create mail item:
Set miOL = applOL.CreateItem(olMailItem)
'Add mail recipients, either the email id or their name in your address book. Invalid ids will result in code error.
Set recptOL = miOL.Recipients.Add(what_address)
recptOL.Type = olTo
Set recptOL = miOL.Recipients.Add("***")
recptOL.Type = olBCC
'with the mail item:
With miOL
'subject of the mail:
.Subject = subject_line
'Chr(10) represents line feed/new line, & Chr(13) represents carriage return. Send text and also contents from the host workbook's worksheet range as Mail Body.
.HTMLBody = mail_body
'set importance level for the mail:
.Importance = olImportanceHigh
'add an attachment to the mail:
.Attachments.Add ("C:\...\Documents\Inkomenszekerheid.pdf")
'send the mail:
.Display
End With
'clear the object variables:
Set applOL = Nothing
Set miOL = Nothing
Set recptOL = Nothing
End Sub
---------------------------------------------------------------------------------------------------------------------------
Sub OutlookMail_2()
row_number = 1
Do
DoEvents
row_number = row_number + 1
Dim mail_body_message As String
Dim full_name As String
mail_body_message = Blad3.Range("A2")
full_name = Blad2.Range("M" & row_number) & " " & Blad2.Range("O" & row_number) & " " & Blad2.Range("P" & row_number)
mail_body_message = Replace(mail_body_message, "replace_name", full_name)
Call OutlookMail_1(Blad2.Range("Q" & row_number), "U heeft toegang tot de website van ***", mail_body_message)
Loop Until row_number = 7
End Sub |
Het gaat mij nu om idd een For loopje die de persoonlijke regel ook meeneemt in het opstellen van die e-mail.
@Witte, ik heb dat geprobeerd maar vond het naar mijn mening niet prettig werken, ook i.v.m. de databases die worden gebruikt. Toch bedankt voor je suggestie.
Alvast bedankt,
[
Voor 0% gewijzigd door
EdgeStronaut op 02-03-2015 10:28
. Reden: typo ]