View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
joeu2004 joeu2004 is offline
external usenet poster
 
Posts: 2,059
Default Possible to Transfer/Open "Read" a text file into VBA Module?

wrote:
Is it possible to Transfer/Open "Read" a text file
into VBA Module?


The following example provides some useful elements. Be sure to read the
notes that follow.

Const path As String = "c:\documents and settings\myname\my
documents\somefile.txt"
Dim data As String
Dim fd As Integer

fd = FreeFile
Open path For Input Access Read As #fd
Do Until EOF(fd)
Line Input #fd, data
' do something useful with data
Loop
Close #fd

Notes:

1. You can use a constant, starting with 1, instead of using FreeFile.

2. If your text file has some structure (e.g. a CSV file), you should also
see the Help page for the Input statement.