excel vba read whole text file at once

7.1k Views Asked by At

I am using CADCAM Software and writing macro code. Here is my basic macro code.

OPEN "C:\Area ratio\etch.txt" FOR INPUT as #1
DO WHILE NOT EOF (1) =1
    LINE INPUT #1, REC$
    if REC$="" then goto jump2
    'PRINT REC$
    y2#=Y2#-200
    Addtext@ x2#,y2#,0,0,REC$
jump2:
LOOP
CLOSE #1
Clearmarkers@
end@

This code will be working fine. but it will read the text and print line by line.

I need to print read whole text file at once.

1

There are 1 best solutions below

2
On
Sub Test()

    'Tools -> References -> Microsoft Scripting Runtime
    Dim fso As New FileSystemObject
    Dim txt As TextStream
    Dim all_text As String

    Set txt = fso.OpenTextFile("c:\Temp\textfile.txt")
    all_text = txt.ReadAll
    txt.Close

End Sub