Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
"Read Only" error when attempting to open EXCEL file | Excel Discussion (Misc queries) | |||
Unable to open a 82 KB XLSM file due to "Too many different cellformats" & "Converter failed to open the file." errors. | Excel Discussion (Misc queries) | |||
"Cannot access read-only document" (I get this error when I try to open an Excel file) | Excel Discussion (Misc queries) | |||
"Cannot access read-only document" (I get this error when I try to open an Excel file) | Setting up and Configuration of Excel | |||
Excel 2002/2003 can not open xls file says "may be read only" | Excel Discussion (Misc queries) |