View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
ajd ajd is offline
external usenet poster
 
Posts: 16
Default copy workbook to new workbook based on cell value

Thanks. I can't get the macro to work though because it has a "file not
found" error. What format does the link to the old file and the name of the
new file need to be in?

Right now within the range called by the macro I have:

K:\XXX\XXX\[oldfilename.xlsx]

and

YYY\[new filename.xlsx] to place the new file in a nested folder within
the active workbook.

I've tried putting apostrophes and with and without brackets and all that,
but with no luck.

Thanks.


"Joel" wrote:

Sub Copyfiles()

Set fscopy = CreateObject("Scripting.FileSystemObject")
RowCount = 1
Do While Range("A" & RowCount) < ""
OldName = Range("A" & RowCount)
NewName = Range("B" & RowCount)
fscopy.CopyFile OldName, NewName

RowCount = RowCount + 1
Loop

End Sub


"ajd" wrote:

I'd like to copy an existing workbook (that's closed, preferably) and name
the copy based on cell values. So, for example in column A of the active
workbook I have a list of different excel workbooks that are closed (with the
file path), and in column B I have a list of names that I want to call the
copied workbooks. For all of the items in the list I'd like to copy the
respective workbook and give it the listed name. I figure I need a VBA loop,
but have no idea on the commands needed. Thanks.