What is the purpose of the LBound and UBound?
This is a way of setting the parameters of the i varaiable to be used in a
For ... Next loop so that it matches the items in the array. Some arrays
are zero base and others are 1 base, so by using LBound (Lower boundary
value of the array) and UBound (Upper biound value) it automatically matches
whatever base is used. If I knew the array base and how many items are in
the array, I could just have easily used the actual numbers.
What do you mean by TEMPLATE being an object variable?
If you have used this syntax:
Set TEMPLATE = 'some workbook
Then it is a variable for a workbook object, or in VBA speak an Object
Variable.
However, If it is in fact a workbook name, it would be used as:
Workbooks("TEMPLATE.xls") 'or whatever file extension applies.
If it is an object variable, then it can be used without quote marks or file
extension and without the preceding qualification of Workbooks, because the
Object Variable points to all of that in memory. Otherwise, as a workbook
name, it needs all the frills to qualify it so VBA will know what to look
for and where to look.
I may decide to read the employee name one at a time as I loop through,
possibly a DO WHILE the variable that holds the employee name <> null
This For ... Next loop does that:
For i = LBound(myNames) To UBound(myNames)
ThisWorkbook.SaveAs FileName:=myPath & "\" & myNames(i) & ".xls"
Next
I used myNames = Array( ) etc. as an example of creating an array of names.
You can substitute your array name in there in three places and it should
work. To test it, put a MsgBox myNames(i) just before the Next and watch it
change on each loop. Of course, use your array name for the MsgBox, also.
Let me know if it works for you.