By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

File system error

P: n/a
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

Jan 15 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

--
Roy-Vidar
Jan 15 '06 #2

P: n/a
"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)

Jan 15 '06 #3

P: n/a
I am just trying to read an html file from disk.

Thanks

Regards

"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
"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)

Jan 15 '06 #4

P: n/a
No reason for FSO then. The following VBA code will read a file line by line
into variable strBuffer.

Dim intFile As Integer
Dim strBuffer As String
Dim strFile As String

strFile = "C:\My Folder\MyFile.html"

intFile = FreeFile()
Open strFile for Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strBuffer
' strBuffer now contains a line of data: work with it

Loop

Close #intFile

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
"John" <Jo**@nospam.infovis.co.uk> wrote in message
news:Wa********************@pipex.net...
I am just trying to read an html file from disk.

Thanks

Regards

"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
"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)


Jan 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.