Hi,

Change to your settings.
It will list the content of your text file line by line, to Excel row by 
rows. You have to list the id to lookup for in another worksheet.
Then you can use a left formula and vlookup to see what if id's match ids 
in another worksheet. 

Sub DialogDossier3()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Worksheets(2) 'change to your worksheets name
Dim fso As Object, fld As Object, sFile As Object
Dim fsTxt As Object, fsFile As Object
Dim i As Integer
Dim CheminDossier As String
Dim sText As String

With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
    .DisplayAlerts = False
End With

'CheminDossier = BrowseFolder("Choisir votre dossier")
CheminDossier = "E:\_tmpVba" 'Change with your folder path, where your txt 
files are

Set fso = CreateObject("scripting.filesystemobject")
Set fld = fso.getfolder(CheminDossier)

i = 1
For Each sFile In fld.Files
    If UCase(Right(sFile.Path, 4)) = UCase(".txt") Then
        
        Set fsTxt = CreateObject("scripting.filesystemobject")
        Set fsFile = fsTxt.opentextfile(sFile, 1, 2)
        
        Do Until fsFile.atendofstream
            ws.Cells(i, 1).Value = fsFile.readline
            i = i + 1
        Loop
        
    End If
Next sFile

With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
    .DisplayAlerts = True
End With

Set wb = Nothing
Set ws = Nothing
Set fso = Nothing: fld = Nothing: sFile = Nothing
Set fsTxt = Nothing: fsFile = Nothing

End Sub

Pascal Baro
multiskills.elementfx.com <http://www.multiskills.elementfx.com>

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

------------------------------------------------------------------------------------------------------
To post to this group, send email to excel-macros@googlegroups.com

Reply via email to