Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default Possible to Transfer/Open "Read" a text file into VBA Module?

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default 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"?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
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.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default 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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Read Only" error when attempting to open EXCEL file Jim Excel Discussion (Misc queries) 1 January 27th 10 06:28 AM
Unable to open a 82 KB XLSM file due to "Too many different cellformats" & "Converter failed to open the file." errors. Phillip Pi Excel Discussion (Misc queries) 0 April 23rd 09 08:53 PM
"Cannot access read-only document" (I get this error when I try to open an Excel file) [email protected] Excel Discussion (Misc queries) 1 June 5th 06 01:15 PM
"Cannot access read-only document" (I get this error when I try to open an Excel file) [email protected] Setting up and Configuration of Excel 1 June 5th 06 01:15 PM
Excel 2002/2003 can not open xls file says "may be read only" Number6 Excel Discussion (Misc queries) 3 December 20th 05 05:25 PM


All times are GMT +1. The time now is 07:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"