I am trying to make a macro that takes the names and details of clients from the data, then creates a separate PDF invoice for each client and emails it to them using outlook ( or any email server for that matter)
I got the template for an invoice. I also watched a video on youtube that showed how to make invoices from excel and how to feed raw data into an invoice template. However, I am pretty much lost after that and the video is of no help either. I am looking for help regarding:
"How to make a separate PDf invoice for each client and email it to them." Here's my code:
Public idk()
'First we define a few variables to capture data from our Excel worksheet
Dim customername As String
Dim customeraddress As String
Dim invoicenumber As Long
Dim r As Long
Dim mydate As String
Dim path As String
Dim myfilename As String
'our last row of data in the worksheet is defined
lastrow = Sheets("CustomerDetails").Range("A" & Rows.Count).End(xlUp).Row
' we start at row 2 since the first row contains headers
r = 2
'Looping process starts
For r = 2 To lastrow
'If the value under the header ‘Note’ is done then the data in the row is not processed and jump to the label next row
'we map excel worksheet data to the variables
customername = Sheets("CustomerDetails").Cells(r, 1).Value
customeraddress = Sheets("CustomerDetails").Cells(r, 2).Value
customercity = Sheets("CustomerDetails").Cells(r, 3).Value
customerstate = Sheets("CustomerDetails").Cells(r, 4).Value
customerzip = Sheets("CustomerDetails").Cells(r, 5).Value
invoicenumber = Sheets("CustomerDetails").Cells(r, 6).Value
invoicedate = Sheets("CustomerDetails").Cells(r, 7).Value
phone = Sheets("CustomerDetails").Cells(r, 8).Value
Email = Sheets("CustomerDetails").Cells(r, 9).Value
MonthlyPayment = Sheets("CustomerDetails").Cells(r, 10).Value
discount = Sheets("CustomerDetails").Cells(r, 11).Value
PolicyNumber = Sheets("CustomerDetails").Cells(r, 12).Value
Application.DisplayAlerts = False
ActiveWorkbook.Sheets("BasicInvoice").Activate
' now we map the variables to the invoice worksheet data
ActiveWorkbook.Sheets("BasicInvoice").Range("C8").Value = customername
ActiveWorkbook.Sheets("BasicInvoice").Range("C9").Value = customeraddress
ActiveWorkbook.Sheets("BasicInvoice").Range("C9").Value = customercity
ActiveWorkbook.Sheets("BasicInvoice").Range("G8").Value = phone
ActiveWorkbook.Sheets("BasicInvoice").Range("G10").Value = Email
ActiveWorkbook.Sheets("BasicInvoice").Range("i14").Value = MonthlyPayment
'Make a PDF of the Invoice
ChDir "C:\Users\Akhtar\Desktop"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Users\Akhtar\Desktop\Experiment", OpenAfterPublish:=True
'our label next row. Labels have a colon after their name
Nextrow:
Next r
End Sub
With this code, I am only able to make one PDF invoice. I need a way to tell excel that I want a separate invoice for all the clients listed.
IDK if I am explaining this well. If you're confused let me know.
I have attached my excel file as well
Here's a link of the video i mentioned above: http://www.exceltrainingvideos.com/u...ting-with-vba/
Bookmarks