Opening af text file in VBA  
Author Message
epimp





PostPosted: Visual Basic for Applications (VBA), Opening af text file in VBA Top

I want to open a random text file in Visual Basic for Applications under MS Access.

First, I just want it to open.

Down the road, I would like to also be able to parse it and take some parts of the file and put those in one table, other parts in another table, do some looking up in the table based on the fourth parts and depending on the result of that look-up insert some fifth parts of the text file in a specific cell.

I've tried the regular import function but it can only put data into one table and there's no mean of manipulating data. One of the entries in the text file is "05MAY2006" which I want to have read as a data.

I only have little experience in the mystic world of VBA and really advanced MS Office usage. I do, however, have lots of programming knowledge from working with PHP, MySQL and Delphi. Am I asking for too much from VBA


Microsoft ISV Community Center Forums2  
 
 
epimp





PostPosted: Visual Basic for Applications (VBA), Opening af text file in VBA Top

Yay! This does part of the trick. Thanks to some more digging in the help file. Thank you MS for help files.

Sorry for wasting your time.

filespec = "C:\file.txt"

Dim fs, f, s

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filespec)
's = f.DateCreated
Set ts = f.OpenAsTextStream(1, -2)
s = ts.ReadAll
ts.Close

Text1.SetFocus
Text1.Text = s