ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   read windows notepad file content into excel? (https://www.excelbanter.com/excel-programming/390239-read-windows-notepad-file-content-into-excel.html)

David

read windows notepad file content into excel?
 
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

moon

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




NickHK

read windows notepad file content into excel?
 
David,
Excel can open text files with the Text Import wizard.
Just open your file from FileOpen and follow the steps. I imagine you need
to set the "Delimited" option, then specify the Delimiter "Other" to "=".
If you record a macro whilst do this, you will get the code.

NickHK

"David" wrote in message
...
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





All times are GMT +1. The time now is 05:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com