Hi all.
I have created VBA code for sending mails with different attachments to different addresses, via Thunderbird. The code looks correct but while creating particular mail bodies it uses still the values from the first line. I.e. while it should send 20 mails to 20 adresses (in each mail different attachment), it create 20 same mails (to the same first adress with the same first attachment).
And the strange fact is that in the debugging window all looks correct and the values are changing.
I will appreciate any help.
I have created VBA code for sending mails with different attachments to different addresses, via Thunderbird. The code looks correct but while creating particular mail bodies it uses still the values from the first line. I.e. while it should send 20 mails to 20 adresses (in each mail different attachment), it create 20 same mails (to the same first adress with the same first attachment).
And the strange fact is that in the debugging window all looks correct and the values are changing.
Code:
<code>Option Explicit
Sub SendMailThunder_Click()
Dim strEmpfaenger1 As String
Dim strBetr As String
Dim strBody As String
Dim strFile2 As Variant
Dim strTh As String
Dim strCommand As Variant
Dim Name As String
Dim Result As Variant
Dim List As Variant
Dim PS As Long
Dim y As Long
Set List = ThisWorkbook.Worksheets("Ridici")
' number of items in the collumn
PS = List.Cells(Rows.Count, 11).End(xlUp).Row
With List
For y = 4 To PS
' Name of attachment
Name = .Cells(y, 12).Value
' selected email to particular driver
strEmpfaenger1 = .Cells(y, 15).Value
strBetr = .Range("O1")
strBody = .Range("O2")
strTh = "C:\Users\alois.konecny\AppData\Local\Mozilla Thunderbird\thunderbird.exe"
' path to attachment
cesta = .Range("N1")
' attachment including path
priloha = "\" & Nazev & ".xls"
result = cesta & priloha
strFile2 = result
strCommand = strCommand & " -compose " & "to=" & Chr(34) & strEmpfaenger1 & Chr(34)
strCommand = strCommand & ",subject=" & Chr(34) & strBetr & Chr(34)
strCommand = strCommand & ",body=" & Chr(34) & strBody & Chr(34)
strCommand = strCommand & ",attachment=" & "file:///" & Replace(strFile2, "\", "/")
Shell strTh & strCommand, vbNormalFocus
Next y
End With
End Sub </code>
I will appreciate any help.