thebest07111
New Member
- Joined
- Aug 22, 2014
- Messages
- 12
i have this code:
it needs to follow this table
number company invoicenumber
1 copmany1 1
2 copmany2 2
3 copmany3 3
4 copmany4 4
5 copmany5 5
6 copmany6 6
but for some reason when i sent the email using the code above it sends the invoice of copmany2 gets invoice number 3 copmany 4 gets invoice number 5 and so on.
How can i fix that?
Code:
Public Sub pdfopslag()
Dim myCell As Range
Dim valRules As Range
path = Range("I21").Text
Set valRules = Evaluate(Range("A9").Validation.Formula1)
Application.ScreenUpdating = True
Worksheets("factuur").UsedRange.Columns("A:G").Calculate
For Each myCell In valRules
emailadres = Application.WorksheetFunction.VLookup(Sheets("factuur").Range("A9"), Sheets("Gegevens").Range("A:G"), 7, False)
roepnaam = Application.WorksheetFunction.VLookup(Sheets("factuur").Range("A9"), Sheets("Gegevens").Range("A:H"), 8, False)
Dim A As String: A = "Beste " & roepnaam
Dim B As String: B = "Hierbij de maandelijkse huurfactuur."
Dim C As String: C = "Met vriendelijke groet,"
Range("A9") = myCell
filename1 = Range("B18").Text
filename2 = Range("A8").Text
PDF_File = path & filename1 & " " & filename2 & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:=PDF_File
On Error Resume Next
Set OutlApp = GetObject(, "Outlook.Application")
If Err Then
Set OutlApp = CreateObject("Outlook.Application")
IsCreated = True
End If
OutlApp.Visible = True
On Error GoTo 0
' Prepare e-mail with PDF attachment
With OutlApp.CreateItem(0)
' Prepare e-mail
.Subject = "Factuur huur"
.To = emailadres
.Attachments.Add PDF_File
.Body = A & vbNewLine & vbNewLine & B & vbNewLine & vbNewLine & C
' Try to send
On Error Resume Next
.Send
Application.Visible = True
If Err Then
MsgBox "E-mail was not sent", vbExclamation
Else
MsgBox "E-mail successfully sent", vbInformation
End If
On Error GoTo 0
End With
Next myCell
Set OutlApp = Nothing
End Sub
it needs to follow this table
number company invoicenumber
1 copmany1 1
2 copmany2 2
3 copmany3 3
4 copmany4 4
5 copmany5 5
6 copmany6 6
but for some reason when i sent the email using the code above it sends the invoice of copmany2 gets invoice number 3 copmany 4 gets invoice number 5 and so on.
How can i fix that?