FileSystemObject

L

lol

I am trying to copy a file within an Excel application
using VBA 6.0. 'Help' says to use a FileSystemObject
which has a Move method. But the VBA development
environment will not let me Dim a variable as a
FileSystemObject. Is there a library that I need to
activate? Or is there a workaround with older commands?
 
R

Rob van Gelder

There are two methods really: Early binding or Late binding.

Early bind:
From the VB Editor menu:
Tools | References
Choose Microsoft Scripting Runtime

Then you can dim a variable as Scripting.FileSystemObject
eg.
Sub test()
Dim fso As Scripting.FileSystemObject
End Sub



In practise, it's sometimes a good idea to late-bind:
(no need to add the Microsoft Scripting Runtime reference)

eg.
Sub test()
Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")
End Sub


Someone may have a pointer to an article discussing the merits of either - I
don't have one handy right now.
 
S

Steve Garman

You could add a reference to the
Microsoft scripting runtime

but you may not need it if you take a look at the FileCopy statement first
 

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