ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Possible to Transfer/Open "Read" a text file into VBA Module? (https://www.excelbanter.com/excel-programming/428736-possible-transfer-open-read-text-file-into-vba-module.html)

[email protected]

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


Rick Rothstein

Possible to Transfer/Open "Read" a text file into VBA Module?
 
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"?

--
Rick (MVP - Excel)


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



Rick Rothstein

Possible to Transfer/Open "Read" a text file into VBA Module?
 
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

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
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"?

--
Rick (MVP - Excel)


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




[email protected]

Possible to Transfer/Open "Read" a text file into VBA Module?
 
Rick, wish to update VBA modules w/o causing issues with Norton A/V inappropriately "seeing" the
bloodhound virus.

"Rick Rothstein" wrote:

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"?


[email protected]

Possible to Transfer/Open "Read" a text file into VBA Module?
 
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.


"Rick Rothstein" wrote:

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


joeu2004

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.


[email protected]

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

"JoeU2004" wrote:

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.



All times are GMT +1. The time now is 11:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com