View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
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.