Read a text file, adding the amounts : Text File « File Path « VBA / Excel / Access / Word






Read a text file, adding the amounts

 
Sub wend()
    Open "C:\Invoice.txt" For Input As #1
    TotalSales = 0
    While Not EOF(1)
        Line Input #1, Data
        TotalSales = TotalSales + Data
    Wend
    MsgBox "Total Sales=" & TotalSales
    Close #1
End Sub

 








Related examples in the same category

1.Create and Save Text file
2.Save Date and Time information to a text file
3.Filtering a text file
4.Read a text file, skipping the Total lines
5.Reading Text Files One Row at a Time
6.Use a Do...While loop to keep reading records until you've reached the end of the file:
7.Writing Text Files