MrExcel Publishing
Your One Stop for Excel Tips & Solutions

How can I copy non Excel files


Posted by Shakes on April 19, 2001 4:40 PM

I need to copy non excel files from one directory to another. I tried to use the FileSystemObject.Copy file method and the FileObject.Copy statements, but they give me an error that says "Object required". Can anyone help me out with this problem?!?

thanks!!


Posted by Dax on April 20, 2001 10:50 AM


Are you using the New keyword when you are dimensioning the FileSystem object? This code will work as long as you set a reference to the Microsoft Scripting Runtime.

Sub CopyAFile()
Dim SourceFile As String
Dim DestinationFolder As String
Dim Fs As New FileSystemObject
SourceFile = InputBox("Please enter source file path", "File Path")
DestinationFolder = InputBox("Please enter destination folder path", "Destination Folder")
If Right(DestinationFolder, 1) <> "/" Then
DestinationFolder = DestinationFolder & "\"
End If
Fs.CopyFile SourceFile, DestinationFolder & "\"
End Sub


Posted by Dax on April 20, 2001 10:54 AM

oooops, typo in above code...


The additional slash on the second to last line isn't needed i.e.

Fs.CopyFile SourceFile, DestinationFolder

Regards,
Dax.