Are there specific scenarios where I should use on of the following or are they interchangeable?
Option 1
...
FileSystem.FileCopy...
...
Option 2
...
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile
...
Or is option 1, under the hood, just option 2 ?
Option 1's FileSystem.FileCopy is the built-in VBA function to copy a file, its part of the core language and always available (you don't need the FileSystem namespace prefix)
Option 2 is more complex; it uses COM to create a late-bound FSO instance and calls a method that has the same name and does the same thing as the built-in.
There seems little benefit in using option 2 over option 1, the only functional difference is that the FSO exposes an argument to control overwrite behaviour, something you would need to deal with manually using the built in FileCopy (trivial enough).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With