Method 'OpenText' of object 'Workbooks' failed

MacroMan
03-14-2003, 12:28 PM
I am experiencing a problem with opening several text files in a directory. We have a database that creates these textfiles at night, and then the next day, we run a VBApps.exe to import these text files into Excel and create several reports. However, it is erroring out on about 5 text files. But, when I remove those 5 text files from the directory, then it can completely run through the remaining text files (there are about 100 text files total). The strange thing is that I can manually open the text files and manipulate them. Does anybody have any ideas as to why this wouldn't work?? The Error Message I get is "Method 'OpenText' of object 'Workbooks' failed". I've never received an error like that before. However, something else I tried was just to loop through the files and open and close just the textfiles that it errored out on. It worked!! But, if I looped through the files and formatted each one, then it would work for the first done, but then error out for the second. I'm totally stumped on this one.

Thanks.


************Code******************

''check text files to determine if they exist
I = 0
fPath = "c:\textfiles\"
fName = Dir(fPath & "A*-" & userinput & ".txt")
While fName <> ""
I = I + 1
ReDim Preserve fileListBilling(1 To I)
fileListBilling(I) = fName
fName = Dir()
Wend

I = 1
Do Until I > UBound(fileListBilling())
.Workbooks.OpenText FileName:="c:\textfiles\" & fileListBilling(I)
******Format Report
.Workbooks(fileListBilling(I)).Close
I = I + 1
Loop

MacroMan
03-17-2003, 09:11 AM
After continuous tests, I believe I have resolved the matter as to why the text files would not open. I don't know why it didn't like it, but the file naming convention seemed to have been causing the error. I altered the names of all the text files that errored out, ran the program, and everything worked accordingly. I hope to look into this matter some more and figure out why it did not like this particular file name.

MacroMan
03-21-2003, 01:23 PM
I began to run the program again, this time starting all over at the beginning of the files, and be the time it got to the 27th textfile it errored out. Most texting will need to be conducted. If anybody has any suggestions, I would really appreciate it.

Thanks....

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum