View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default How to copy a workbook

WLMPilot wrote on 5/10/2010 :
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


If you're looking to just copy a template file rather than an open
workbook:

'''''''''''''''''''
Dim i As Integer

Const sSourceFile As String = "C:\MyTemplate.xls" 'change to suit
Const STargetPath As String = "C:\MyFolder\" 'change to suit

'Iterate your employees array and assign the names to the copied file
For i = LBound(asMyEmployees) To UBound(asMyEmployees)
FileCopy sSourceFile, sTargetPath & asMyEmployees(i) & ".xls"
Next
'''''''''''''''''''
--
Garry