Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Pulling pdf files from general folder to specific folder | Excel Discussion (Misc queries) | |||
copying data from folder to folder | New Users to Excel | |||
Copying Cells from CSV files in folder into one worksheet | Excel Discussion (Misc queries) | |||
Copying all files in a folder to new folder | Excel Discussion (Misc queries) | |||
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? | Excel Discussion (Misc queries) |