Copying a file with VBA (or with a SHELL command)

F

Franck V.

Hi,

I'm looking for a solution to make a copy of a file already open.
Function FILECOPY doesn't work because this file is already open...
The file I want to copy is a SYS file so it's impossible to open it in Excel
and save it as...

Would anyone have an idea about it ? If yes, could you please write me a
line of code as example.

Thanks,

Franck V.
 
T

Tom Ogilvy

You would need to create a reference to the Microsoft Scripting Runtime in
the VBE under tools references. If you don't want to do that, you can use
late binding

Sub TestCopy()
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile "C:\test.sys", "D:\My Folder\"

End Sub

Make sure you include the last "\" in the destination.

this assume you have the scripting runtime installed - which is highly
probable.

so the original should have been

Dim FSO as FileSystemObject
set FSO = new FileSystemObject
FSO.CopyFile "C:\test.sys", "D:\My Folder\"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top