View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz[_2_] JLGWhiz[_2_] is offline
external usenet poster
 
Posts: 1,565
Default How to copy a workbook

Hi Les, Since you have the emplyee names in an array, you can use the array
name as the variable to name the workbook.

myNames = Array(Name1, Name2, Name3....Namen)
myPath = ThisWorkbook.Path '<<<assumes same folder as master
For i = LBound(myNames) To UBound(myNames)
ThisWorkbook.SaveAs FileName:=myPath & "\" & myNames(i) & ".xls"
Next

The SaveAS method is creating a copy of the master workbook and naming it
with a name from the array of employee names. This assumes the array of
names is for new employees only. If not, then you would have to create a
separate variable for the new employee name and use that where the
myNames(i) array variable is used above.




"WLMPilot" wrote in message
...
Thanks. I apologize for not making this clearer. I will have a MASTER
workbook that is used by the boss. Inside the Master workbook will be a
commandbutton to execute a macro that will copy the TEMPLATE workbook and
rename it to match the employee(s) name.

There will be a list of all employees in the Master workbook that I will
read into an array to initially set everything up to match the current
employees. After that, I will have it worked out to copy the TEMPLATE for
each new employee.

Therefore, the code is actually in the MASTER workbook. I wanted to know
what the actual code that will copy the TEMPLATE and rename it (using a
variable that holds the employee's name) will be. I believe I will be
able
to add that addition code to read the names.

Thanks,
Les

"Mike H" wrote:

Hi,

This would go in your 'template' workbook.

This string
S = "aaa,bbb,ccc"

should be changed to your list of employees


Sub Sonic()
Dim V As Variant
Dim S As String

S = "aaa,bbb,ccc"
V = Split(S, ",")
For x = 0 To UBound(V)
ThisWorkbook.SaveAs Filename:=V(x)
Next x
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"WLMPilot" wrote:

I need to know how to copy a workbook in a macro (Excel 2002)
The filename of the workbook to be copied is "Template" (w/o quotes)
The new workbook will have the name of an employee, ie several
workbooks,
each having the name of an employee.

Variable: EMP = "John Doe"
Code needed to copy workbook TEMPLATE and rename to variable EMP.

Thanks,
Les