How to read a textfile line by line in VBA

To read a textfile line by line in VBA you can use the following snippet.
To read a textfile complete into a string you can use How to read a textfile in VBA.

Sample VBA

public sub ReadTextFileLinebyLine()
    Dim sFileName As String
    Dim iFile As Integer
    Dim sLine As String

	on error goto errorhandler
    sFileName = "C:\Users\Codesnippets\Desktop\Test.txt"
	
	If Len(Dir$(sFileName)) = 0 Then
        Exit Sub
    End If

    iFile = FreeFile()
    Open sFileName For Input As iFile

    Do While Not EOF(iFile)
        Line Input #iFile, sLine
        Debug.Print sLine 
    Loop

    Close iFile
	exit sub
	
errorhandler:
'handle the error your way
End Sub

Please rate this snippet

How to list the installed software using vbscript

to list installed software in vbscript you can use the following snippet.
It will export a CSV file with the installed software.

Sample VBScript

Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystemObject.CreateTextFile("C:\CodesnippetsFesslersoft_InstalledSoftware.csv", True)
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colInstalledSoftware = objWMI.ExecQuery("Select * from Win32_Product")

'Header
objFile.WriteLine "" & chr(34) & "Caption" & chr(34) & ";" & chr(34) & "Description" & chr(34) & ";" & chr(34) & "Identifying Number" & chr(34) & ";" & chr(34) & "Install Date" & chr(34) & ";" & chr(34) & "Install Location" & chr(34) & ";" & chr(34) & "Install State" & chr(34) & ";" & chr(34) & "Name" & chr(34) & ";" & chr(34) & "Package Cache" & chr(34) & ";" & chr(34) & "SKU Number" & chr(34) & ";" & chr(34) & "Vendor" & chr(34) & ";" & chr(34) & "Version" & chr(34) & ";" 
		
'content
For Each objInstalledSoftware in colInstalledSoftware
	on error resume next
	objFile.WriteLine  chr(34) & objInstalledSoftware.Caption & chr(34) & ";" & chr(34) & objInstalledSoftware.Description & chr(34) & ";" & chr(34) & objInstalledSoftware.IdentifyingNumber & chr(34) & ";" & chr(34) & objInstalledSoftware.InstallDate2 & chr(34) & ";" & chr(34) & objInstalledSoftware.InstallLocation & chr(34) & ";" & chr(34) & objInstalledSoftware.InstallState & chr(34) & ";" &  chr(34) & objInstalledSoftware.Name & chr(34) & ";" & chr(34) & objInstalledSoftware.PackageCache & chr(34) & ";" & chr(34) & objInstalledSoftware.SKUNumber & chr(34) & ";" & chr(34) & objInstalledSoftware.Vendor & chr(34) & ";" & chr(34) & objInstalledSoftware.Version & chr(34) & ";"
Next
objFile.Close

Call msgbox("done",0,"codesnippets.fesslersoft.de")

Please rate this snippet