Wrong attachment to wrong person

thebest07111

New Member
Joined
Aug 22, 2014
Messages
12
i have this code:


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?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top