CopyFile command

kmiles

Board Regular
Joined
Apr 1, 2002
Messages
113
I am trying to combine multiple text files into one text file prior to importing and working with the data.

When I run the following code I get the error 'Object Required'

FileSystemObject.CopyFile "c:mydocumentslog*.txt", "c:mydocumentscombined.txt"

I'm sure I'm missing something simple.

Thanks for any help.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
On 2002-09-01 17:56, kmiles wrote:
I am trying to combine multiple text files into one text file prior to importing and working with the data.

When I run the following code I get the error 'Object Required'

FileSystemObject.CopyFile "c:mydocumentslog*.txt", "c:mydocumentscombined.txt"

I'm sure I'm missing something simple.

Thanks for any help.

Hi kmiles
You will need to set a reference to the
[Microsoft Scripting Runtime]

<pre/>
Sub CopyI()
'// You need to either
'// 1) Set a reference to the [Microsoft Scripting Runtime]
FileSystemObject.CopyFile "c:mydocumentslog*.txt", "c:mydocumentscombined.txt"

'// OR 2) create the reference via Late Binding
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "c:mydocumentslog*.txt", "c:mydocumentscombined.txt"


'// OR 3) Use VBA to copy
FileCopy "c:mydocumentslog*.txt", "c:mydocumentscombined.txt"

End Sub
</pre>
 
Upvote 0
Hi kmiles
You will need to set a reference to the
[Microsoft Scripting Runtime]

<pre/>
Sub CopyI()
'// You need to either
'// 1) Set a reference to the [Microsoft Scripting Runtime]
FileSystemObject.CopyFile "c:mydocumentslog*.txt", "c:mydocumentscombined.txt"

'// OR 2) create the reference via Late Binding
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "c:mydocumentslog*.txt", "c:mydocumentscombined.txt"


'// OR 3) Use VBA to copy
FileCopy "c:mydocumentslog*.txt", "c:mydocumentscombined.txt"

End Sub
</pre>

[/quote]

Hi Ivan,

Thanks for the info but it seems that none of these commands work with the wildcard '*' in the source path. Removing it allows them to work. I need to copy multiple files into one so did I miss something or is there another option?

The only thing I've been anle to make work is create a dos batch file and execute it via the shell command, but I really don't want to have to use an external batch file.

Thanks again.
 
Upvote 0
OOps, totally misread the question...

I´ll check into this to see if I can find a solution for it :smile:
This message was edited by XL-Dennis on 2002-09-02 11:38
 
Upvote 0
Dennis,

I don't think I made myself clear. What I need to do is concatenate multiple text files into one combined text file.

Sorry about that... any ideas?
 
Upvote 0
Dennis,

I know this should work, but it does not. I can see the DOS window opening and closing during the execution of that line but the copy is not completing and I am getting a return value of -376191 and it is typed correctly.

I am at a loss, I'll try it on my Excel at work tomorrow (v2002) vs (v2000) here at home. I don't know what else to try.

Thanks for the help anyway.
 
Upvote 0
Dennis,

Success!! Converting the double backslashes to single ones corrected the problem. Works great.

Thanks for all of your help.
 
Upvote 0

Forum statistics

Threads
1,225,851
Messages
6,187,386
Members
453,424
Latest member
rickysuwadi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top