Text to excel

Ewright8

New Member
Joined
May 7, 2009
Messages
11
I have 240 text files (dxdiag reports from 240 different computers) that I would like to put into an excel spreadsheet. I do not need all of the file but would like to have about nine different lines from the file placed in cells with one row representing each file (computer). Is this possible or does anyone have any suggestions how I may go about this without having to type all the data in manually.
 
This works for me.
Code:
Sub ListDX()
Dim rng As Range
Dim fs, f, f1, fc, s
Dim LastRow As Long
Dim strPath As String
    strPath = "C:\DX\" 'This is the Directory the files are located in
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(strPath)
    Set fc = f.Files
    Set rng = Worksheets(1).Range("A2")
    
    rng.Offset(-1).Resize(, 7).Value = Array("Machine name", "Operating System", "Processor", "Memory", _
                                                               "Card name", "Description", "FileName")
    
    For Each f1 In fc
    
        Open strPath & f1.Name For Input As #1
        
            Do Until InStr(info, "Description:")
            
                Line Input #1, info
                
                If info <> "" Then ' check for blank lines
                
                    x = Split(info, ":")
                    
                    If Trim(x(0)) = "Machine name" Then
                        rng.Value = Trim(x(1))
                    End If
                    If Trim(x(0)) = "Operating System" Then
                        rng.Offset(, 1).Value = Trim(x(1))
                    End If
                    If Trim(x(0)) = "Processor" Then
                        rng.Offset(, 2).Value = Trim(x(1))
                    End If
                    If Trim(x(0)) = "Memory" Then
                        rng.Offset(, 3).Value = Trim(x(1))
                    End If
                    If Trim(x(0)) = "Card name" Then
                        rng.Offset(, 4).Value = Trim(x(1))
                    End If
                    If Trim(x(0)) = "Description" Then
                        rng.Offset(, 5).Value = Trim(x(1))
                    End If
                    
                End If
                
            Loop
                
            rng.Offset(, 6).Value = f1.Name
            
        Close #1
        
        info = ""
    
        Set rng = rng.Offset(1)
    
    Next
End Sub
The latest problem was due to blank lines, my method of extracting the data (Split) would fall down when encountering one, so I added an If.

If you were to use InStr then that might not be needed.

Anyways the code seems to work for me, mind you I did only test it on 5 files which were all the same but I added the filenames.:)

By the way, you do realise there is more than one item called Description?

The above code only picks up the first one.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
This works great. Thank you very much. I am trying to pull the name of the sound card and this is what it seems to be pulling so any other "Description" fields seem to be getting overlooked for some reason but that works for me. Again thank you very much for your expertise and professionalism.
 
Upvote 0
Well my files seem to be returning the description for some sort of speaker(s) rather than a sound card.

Mind you I'm pretty sure my machine will have bog-standard audio.:)
 
Upvote 0

Forum statistics

Threads
1,216,176
Messages
6,129,316
Members
449,501
Latest member
Amriddin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top