Hi guys,
I've been asked to make several thousand invoices, so i thought i'd use VBA to generate them for me to save me ALOT of time. Each invoice look the same, but has to have a unique name and contain a unique vendornumber in cell B3.
I have 2 column (A and B). A is the name of the excel file i want to make, B is the unique vendornumber i want to be placed in B3 on all of the files i make. Everyone file has to be based on the same template. There are hundreds unique of ID's in each column.
So if a row in my table looks like this:
A2 has the value NAME1.
B2 has the value 9999
Then i'd like to create an excel file (based on my template) called NAME1, that contains 9999 in the B3 cell.
So far i've been able to generate as many excel files as i list in column A with the correct name and correct template. But i can't figure out how i get a unique vendornumber in the B3 cell in each file.
This is my code so far:
I really hope you guys can help me, i'm stuck. Yet i have a feeling the answer might be simple.
What should i add to make this work?
I've been asked to make several thousand invoices, so i thought i'd use VBA to generate them for me to save me ALOT of time. Each invoice look the same, but has to have a unique name and contain a unique vendornumber in cell B3.
I have 2 column (A and B). A is the name of the excel file i want to make, B is the unique vendornumber i want to be placed in B3 on all of the files i make. Everyone file has to be based on the same template. There are hundreds unique of ID's in each column.
So if a row in my table looks like this:
A2 has the value NAME1.
B2 has the value 9999
Then i'd like to create an excel file (based on my template) called NAME1, that contains 9999 in the B3 cell.
So far i've been able to generate as many excel files as i list in column A with the correct name and correct template. But i can't figure out how i get a unique vendornumber in the B3 cell in each file.
This is my code so far:
Code:
Public Sub SaveTemplate()
Const strSavePath As String = "C:\Users\Desktop\Invoice testing\"
Const strTemplatePath As String = "C:\Users\Desktop\Invoice testing\Template\Invoice Template without VAT1.xlsx"
Dim rngNames As Excel.Range
Dim rng As Excel.Range
Dim wkbTemplate As Excel.Workbook
Set rngNames = ThisWorkbook.Worksheets("Sheet1").Range("A2:A200").Cells
Set wkbTemplate = Application.Workbooks.Open(strTemplatePath)
For Each rng In rngNames.Cells
wkbTemplate.SaveAs strSavePath & rng.Value
Set wkbTemplate = ActiveWorkbook
wkbTemplate.Save
Next rng
wkbTemplate.Close SaveChanges:=False
End Sub
I really hope you guys can help me, i'm stuck. Yet i have a feeling the answer might be simple.
What should i add to make this work?