"RoyVidar" <ro*************@yahoo.no> wrote in message
news:mn***********************@yahoo.no...
John wrote in message <OL**************@TK2MSFTNGP11.phx.gbl> : Hi
I am getting the 'User defined type not defined' on the line;
Dim fso As Scripting.FileSystemObject.
What am I doing wrong? What reference do I need to add? Do I need to
install/enable scripting on the win xp sp2 machine?
Thanks
Regards
The reference, I think, is Microsoft Scripting Runtime (in VBE - Tools |
References), or try late binding.
To use Late Binding (which would be my vote if you have to use FSO), you'd
use
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Note that when you use Late Binding, any intrinsic constants defined by the
Scripting library are unavailable to you: you either need to define the
constants yourself, or replace them by the actual value of the constant. For
example, you couldn't use:
Dim fso As Object
Dim f As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile("test1.txt")
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
You'd either have to include a line:
Const ForWriting = 2, TristateUseDefault = -2
or rewrite the code as
Dim fso As Object
Dim f As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile("test1.txt")
Set ts = f.OpenAsTextStream(2, -2)
Are you sure, though, that you need FSO? There's extremely little that FSO
can do that you can't already do in VBA.
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)