Possible to Transfer/Open "Read" a text file into VBA Module?

R

Rick Rothstein

You might want to provide a little more detail in your question. What did
you have in mind by "transfer"? You can open a text file and read its
contents into a String variable easy enough... but what are you looking to
do with it afterwards that you restricted your question to a "VBA Module"?
 
R

Rick Rothstein

Sorry, I meant to give you the code to read in the file...

Dim X As Long
Dim FileNum As Long
Dim TotalFile As String
.....
.....
FileNum = FreeFile
Open "C:\TEMP\TestData.txt" For Binary As #FileNum
TotalFile = Space(LOF(FileNum))
Get #FileNum, , TotalFile
Close #FileNum
'
' The TotalFile variable now contains the entire text from
' the file specified in the Open statement (obviously change
' the same file name and path to the one you want
 
E

EagleOne

Rick, wish to update VBA modules w/o causing issues with Norton A/V inappropriately "seeing" the
bloodhound virus.
 
E

EagleOne

Rick,

Thanks for your time and knowledge!

'Kinda thought of the approach. I just wondered if there were alternate approaches.
Working on alt's to protect VBA code.
 
J

JoeU2004

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.
 
E

EagleOne

Thanks Joe

JoeU2004 said:
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.
 

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