read windows notepad file content into excel?
Two methods:
'Method 1.
Public Sub ImportTextFile1()
Dim txtFile, txtTemp, FileContents As String
Dim fileNum As Integer
txtFile = "C:\SAMPLE.txt"
FileContents = vbNullString
txtTemp = vbNullString
fileNum = FreeFile()
Open txtFile For Input As #fileNum
Do While Seek(fileNum) <= LOF(fileNum)
Line Input #fileNum, txtTemp
FileContents = FileContents & txtTemp & vbCrLf
Loop
Close #fileNum
MsgBox FileContents
End Sub
'Method 2.
Public Sub ImportTextFile2()
Dim fso, f
Dim FileContents As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("C:\SAMPLE.txt")
FileContents = f.ReadAll
f.Close
MsgBox FileContents
End Sub
"David" schreef in bericht
...
Greetings
I have many notepad files that i pick through manually and copy/paste info
out to excel. The notepad file content is logically structured ('bananas =
yellow' in file1, 'bananas = green' in file2 etc. sort of thing). Is it
possible for an excel macro to retrieve external file content like this?
Many Thanks
|