Error: Method 'OpenTextFile' of object 'IFileSystem' failed

L

Learner

I have a VBA macro on MS Excel that should open and read from a Text
file. This is the code


Dim fs, Tempfile
Set fs = CreateObject("Scripting.FileSystemObject")
Set TempFile = fs.OpenTextFile(strInputFile, 1, False)
Do While TempFile.AtEndOfLine <> True
' Process
Loop


I found that it throws error in the OpenTextFile mothod above..


It works for all of our users but one. One guy is getting this strange
error meesage when the code executes. I checked his MS excel and found
its same as mine, Office 2003 SP1 (The code works fine in my machine).


Can you GURUS please help me on this.....
 
T

Tom Ogilvy

check if your problematic user can open the file from their computer.

Maybe they don't have permissions to that file.
 
L

Learner

Tom,

yes, that user can manually open the file smoothly....

checked and also found that he has the latest version of scrrun.dll
 
T

Tom Ogilvy

I would just use the built in FileIO to process the file and see if that
works.

http://www.applecore99.com/gen/gen029.asp



An example:

Sub ReadStraightTextFile()
Dim sStr as String
Dim LineofText As String
Dim rw as Long
rw = 0
Open "C:\FILEIO\TEXTFILE.TXT" For Input As #1
sStr = ""
Do While Not EOF(1)
Line Input #1, LineofText
sStr = sStr & lineofText
if len(sStr) >= 178 then
rw = rw + 1
cells(rw,1).Value = sStr
sStr = ""
End if
Loop
'Close the file
if len(sStr) > 0 then
cells(rw,1).Value = sStr
End if
Close #1
End Sub
 
L

Learner

I tried this and the Builtin I/O gave a different error. This time it
is 52 : Bad File number or name

I looked at MSN KB and it says the problem is because of some bad file
names such as
starting with a ", /, lessthan 4 characters in filename etc. (My txt
file is simple and its like
\\FullyQualifiedSharedServer\SharedFolder\Mydata.txt ) I am mostly
certain that this is because the txt file is in the share and this user

may not have default access to it (Meaning, when he manually double
clicks on the txt file in question, he is getting a prompt to supply
user id and password). So my question is, what is the workaround on it
? IOW, is it possible to supply UserId/Password as part of the OPEN
statement ?..
 

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