Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   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

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default copy workbook to new workbook based on cell value

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.

  #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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default copy workbook to new workbook based on cell value


The code should work just fine for you if you leave it as it was posted,
the code posted doesn't change the filepath (which is what you are
having a problem with "K:\xx....etc"), do you need it saved to a
different filepath?, try to be a little more descriptive of your need so
we can provide you with a satisfactory answer.

ajd;213833 Wrote:
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.



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=58645

  #5   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

The original files are all in the same folder with a path similar to:

K:\XXX\YYY\

and are .xlsx files

The active workbook with the list of original files to copy and the list new
of names is in a path similar to:

K:\ZZZ\AAA\ (ie. totally different location)

I'd like the program to copy the appropriate file (named in Column A of the
active sheet) in the K:\XXX\YYY\ folder and paste it in a folder with the
path: K:\ZZZ\AAA\BBB with the name listed in Column B.

While I think the code provided will work, for whatever reason it isn't
recognizing the file path that I have listed in Column A. The file path I
have listed in column A is K:\XXX\YYY\[original file name1.xlsx]. The new
file name I have listed is BBB\[new file name1.xlsx]

The error is "file not found", so I'm guessing it has to do with the
original file name path.

Thanks again.


"Simon Lloyd" wrote:


The code should work just fine for you if you leave it as it was posted,
the code posted doesn't change the filepath (which is what you are
having a problem with "K:\xx....etc"), do you need it saved to a
different filepath?, try to be a little more descriptive of your need so
we can provide you with a satisfactory answer.

ajd;213833 Wrote:
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.



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=58645




  #6   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

Never mind, I figured out a workaround. And apparently the brackets aren't
needed. Thanks.

"ajd" wrote:

The original files are all in the same folder with a path similar to:

K:\XXX\YYY\

and are .xlsx files

The active workbook with the list of original files to copy and the list new
of names is in a path similar to:

K:\ZZZ\AAA\ (ie. totally different location)

I'd like the program to copy the appropriate file (named in Column A of the
active sheet) in the K:\XXX\YYY\ folder and paste it in a folder with the
path: K:\ZZZ\AAA\BBB with the name listed in Column B.

While I think the code provided will work, for whatever reason it isn't
recognizing the file path that I have listed in Column A. The file path I
have listed in column A is K:\XXX\YYY\[original file name1.xlsx]. The new
file name I have listed is BBB\[new file name1.xlsx]

The error is "file not found", so I'm guessing it has to do with the
original file name path.

Thanks again.


"Simon Lloyd" wrote:


The code should work just fine for you if you leave it as it was posted,
the code posted doesn't change the filepath (which is what you are
having a problem with "K:\xx....etc"), do you need it saved to a
different filepath?, try to be a little more descriptive of your need so
we can provide you with a satisfactory answer.

ajd;213833 Wrote:
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.



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=58645


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding a Workbook based on a Cell information in another Workbook Walter Excel Worksheet Functions 1 October 10th 09 08:46 AM
Copy cells based on conditions in one workbook to another workbook fLiPMoD£ Excel Discussion (Misc queries) 0 August 1st 07 07:43 PM
Copy cells based on conditions in one workbook to another workbook fLiPMoD£ Excel Worksheet Functions 0 August 1st 07 07:43 PM
Copy cells based on conditions in one workbook to another workbook fLiPMoD£ Excel Programming 0 August 1st 07 07:43 PM
Copy cell data from workbook based on user input Michael A Excel Programming 7 December 31st 05 03:07 PM


All times are GMT +1. The time now is 10:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"