Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Extracting/copying files from a folder using VBA

Hi all,

I have a folder (i.e. c:\current) that contains around 5000 csv files, and I
have a list of around 200 off these files that I need to copy and paste to a
new folder i.e. (c:\new).

Rather than find each file manually or use the search function, is there a
way i can tell vba to search through c:\current for the filenames that I
specify and then copy and paste them to c:\new?

Any help would be much appreciated.

Kind Regards,

Bhupinder.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Extracting/copying files from a folder using VBA

assume the list of 200 is in column A of the activesheet and the file names
are like a.csv or aaa.csv rather than c:\current\aaa.csv

Sub copysomefiles()
Dim cell as Range
for each cell in Range("A1:A200")
filecopy "c:\current\" & cell.name, "c:\new\ & cell.name"
Next
end Sub

--
Regards,
Tom Ogilvy


"Bhupinder Rayat" wrote in
message ...
Hi all,

I have a folder (i.e. c:\current) that contains around 5000 csv files, and

I
have a list of around 200 off these files that I need to copy and paste to

a
new folder i.e. (c:\new).

Rather than find each file manually or use the search function, is there a
way i can tell vba to search through c:\current for the filenames that I
specify and then copy and paste them to c:\new?

Any help would be much appreciated.

Kind Regards,

Bhupinder.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Extracting/copying files from a folder using VBA

Tom,

excel doesn't like line 4 (filecopy....), it returns an error message saying
'Application defined or object defined error'.

I double-checked the names and filepaths, which are correct. Any ideas?

Regards,

Bhupinder.

"Tom Ogilvy" wrote:

assume the list of 200 is in column A of the activesheet and the file names
are like a.csv or aaa.csv rather than c:\current\aaa.csv

Sub copysomefiles()
Dim cell as Range
for each cell in Range("A1:A200")
filecopy "c:\current\" & cell.name, "c:\new\ & cell.name"
Next
end Sub

--
Regards,
Tom Ogilvy


"Bhupinder Rayat" wrote in
message ...
Hi all,

I have a folder (i.e. c:\current) that contains around 5000 csv files, and

I
have a list of around 200 off these files that I need to copy and paste to

a
new folder i.e. (c:\new).

Rather than find each file manually or use the search function, is there a
way i can tell vba to search through c:\current for the filenames that I
specify and then copy and paste them to c:\new?

Any help would be much appreciated.

Kind Regards,

Bhupinder.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Extracting/copying files from a folder using VBA

there was a typo in my code:

Sub copysomefiles()
Dim cell as Range
for each cell in Range("A1:A200")
filecopy "c:\current\" & cell.name, "c:\new\" & cell.name
Next
end Sub


Just for confidence, As you can see from this demo in the immediate window:

? dir("c:\data\A*.xls")
aaa_date_test.xls
filecopy "c:\data\aaa_date_test.xls", "c:\data1\aaa_date_test.xls"
? dir("c:\data1\aaa_date_test.xls")
aaa_date_test.xls

filecopy works very well when properly constructed.
--
Regards,
Tom Ogilvy


"Bhupinder Rayat" wrote in
message ...
Tom,

excel doesn't like line 4 (filecopy....), it returns an error message

saying
'Application defined or object defined error'.

I double-checked the names and filepaths, which are correct. Any ideas?

Regards,

Bhupinder.

"Tom Ogilvy" wrote:

assume the list of 200 is in column A of the activesheet and the file

names
are like a.csv or aaa.csv rather than c:\current\aaa.csv

Sub copysomefiles()
Dim cell as Range
for each cell in Range("A1:A200")
filecopy "c:\current\" & cell.name, "c:\new\ & cell.name"
Next
end Sub

--
Regards,
Tom Ogilvy


"Bhupinder Rayat" wrote in
message ...
Hi all,

I have a folder (i.e. c:\current) that contains around 5000 csv files,

and
I
have a list of around 200 off these files that I need to copy and

paste to
a
new folder i.e. (c:\new).

Rather than find each file manually or use the search function, is

there a
way i can tell vba to search through c:\current for the filenames that

I
specify and then copy and paste them to c:\new?

Any help would be much appreciated.

Kind Regards,

Bhupinder.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Extracting/copying files from a folder using VBA

Tom,

I picked up on your typo before and tried to run it, but still the same
error message came up.

What does that error message relate to, my limited vba knowledge doesn't
allow me to decipher microsoft help's interpretation of it.

Thanks for your help.

Bhupinder.
"Tom Ogilvy" wrote:

there was a typo in my code:

Sub copysomefiles()
Dim cell as Range
for each cell in Range("A1:A200")
filecopy "c:\current\" & cell.name, "c:\new\" & cell.name
Next
end Sub


Just for confidence, As you can see from this demo in the immediate window:

? dir("c:\data\A*.xls")
aaa_date_test.xls
filecopy "c:\data\aaa_date_test.xls", "c:\data1\aaa_date_test.xls"
? dir("c:\data1\aaa_date_test.xls")
aaa_date_test.xls

filecopy works very well when properly constructed.
--
Regards,
Tom Ogilvy


"Bhupinder Rayat" wrote in
message ...
Tom,

excel doesn't like line 4 (filecopy....), it returns an error message

saying
'Application defined or object defined error'.

I double-checked the names and filepaths, which are correct. Any ideas?

Regards,

Bhupinder.

"Tom Ogilvy" wrote:

assume the list of 200 is in column A of the activesheet and the file

names
are like a.csv or aaa.csv rather than c:\current\aaa.csv

Sub copysomefiles()
Dim cell as Range
for each cell in Range("A1:A200")
filecopy "c:\current\" & cell.name, "c:\new\ & cell.name"
Next
end Sub

--
Regards,
Tom Ogilvy


"Bhupinder Rayat" wrote in
message ...
Hi all,

I have a folder (i.e. c:\current) that contains around 5000 csv files,

and
I
have a list of around 200 off these files that I need to copy and

paste to
a
new folder i.e. (c:\new).

Rather than find each file manually or use the search function, is

there a
way i can tell vba to search through c:\current for the filenames that

I
specify and then copy and paste them to c:\new?

Any help would be much appreciated.

Kind Regards,

Bhupinder.








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Extracting/copying files from a folder using VBA

Application Defined or Object defined error:
the only object in the command is Cell which is defined in my sample.

As I demonstrated, supplied with proper arguments, filecopy works fine.

I tried several different flawed constructs for filecopy and never received
that error.

filecopy does require that the workbook not be opened or the file not in use
at the time it is copied.

--
Regards,
Tom Ogilvy


"Bhupinder Rayat" wrote in
message ...
Tom,

I picked up on your typo before and tried to run it, but still the same
error message came up.

What does that error message relate to, my limited vba knowledge doesn't
allow me to decipher microsoft help's interpretation of it.

Thanks for your help.

Bhupinder.
"Tom Ogilvy" wrote:

there was a typo in my code:

Sub copysomefiles()
Dim cell as Range
for each cell in Range("A1:A200")
filecopy "c:\current\" & cell.name, "c:\new\" & cell.name
Next
end Sub


Just for confidence, As you can see from this demo in the immediate

window:

? dir("c:\data\A*.xls")
aaa_date_test.xls
filecopy "c:\data\aaa_date_test.xls", "c:\data1\aaa_date_test.xls"
? dir("c:\data1\aaa_date_test.xls")
aaa_date_test.xls

filecopy works very well when properly constructed.
--
Regards,
Tom Ogilvy


"Bhupinder Rayat" wrote in
message ...
Tom,

excel doesn't like line 4 (filecopy....), it returns an error message

saying
'Application defined or object defined error'.

I double-checked the names and filepaths, which are correct. Any

ideas?

Regards,

Bhupinder.

"Tom Ogilvy" wrote:

assume the list of 200 is in column A of the activesheet and the

file
names
are like a.csv or aaa.csv rather than c:\current\aaa.csv

Sub copysomefiles()
Dim cell as Range
for each cell in Range("A1:A200")
filecopy "c:\current\" & cell.name, "c:\new\ & cell.name"
Next
end Sub

--
Regards,
Tom Ogilvy


"Bhupinder Rayat" wrote

in
message ...
Hi all,

I have a folder (i.e. c:\current) that contains around 5000 csv

files,
and
I
have a list of around 200 off these files that I need to copy and

paste to
a
new folder i.e. (c:\new).

Rather than find each file manually or use the search function, is

there a
way i can tell vba to search through c:\current for the filenames

that
I
specify and then copy and paste them to c:\new?

Any help would be much appreciated.

Kind Regards,

Bhupinder.








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
Pulling pdf files from general folder to specific folder [email protected] Excel Discussion (Misc queries) 2 September 8th 09 09:41 PM
copying data from folder to folder RPW New Users to Excel 1 March 2nd 07 02:20 PM
Copying Cells from CSV files in folder into one worksheet [email protected] Excel Discussion (Misc queries) 1 June 23rd 06 09:23 PM
Copying all files in a folder to new folder michaelberrier Excel Discussion (Misc queries) 2 June 20th 06 05:35 AM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM


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

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"