Vba read all text in a text file?

I am trying to use vba to read all the text in a text file and display it in an excel message box. The problem that I have while it works, is it displaying each line of text in a separate message box, when instead I want it all in one?

Can someone please show me where I am wrong. thanks

If Range("L" & ActiveCell.Row).Value = "Performance" Then
Dim FilePath As String
Dim strLine As String
FilePath = "\\UKSH000-FILE06\Purchasing\New_Supplier_Set_Ups_&_Audits\ATTACHMENTS\" & Range("C" & ActiveCell.Row).Value & "\performance.txt"
Open FilePath For Input As #1
While EOF(1) = False
    'read the next line of data in the text file
    Line Input #1, strLine
    'print the data in the current row
    MsgBox strLine
    'increment the row counter
    i = i + 1
Wend
Close #1

End If
0
source share
2 answers

In your loop, you must concatenate all the lines of the string variable and output the result at the end. This is basically the case:

Dim Total As String
' ...
While EOF(1) = False
    'read the next line of data in the text file
    Line Input #1, strLine
    Total = Total & vbNewLine & strLine
    'increment the row counter
    i = i + 1
Wend

MsgBox Total

. , - , , , , . . , 1000 , 999 .

+1

:

  • Dim strAll As String .
  • MsgBox strAll = strAll & strLine.
  • MsgBox strAll

& VBA. :

strAll = strAll & " " & strLine.

strAll = strAll & vbCrLf & strLine.

vbCrLf - VBA, " , ". /, !

+1

Source: https://habr.com/ru/post/1626148/


All Articles