Print a Text File

By | 2019-10-02

Simple method to print a text file to the default printer.

Module

Option Explicit

Public Sub PrintTXTFile(FileName As String)
    Dim x As Integer
    Dim s As String

    x = FreeFile
    On Error GoTo HandleError
    Open FileName For Input As x
    Do While Not EOF(x)
        Line Input #x, s
        Printer.Print s
    Loop
    Printer.EndDoc
    Close #x
    Exit Sub
HandleError:
    MsgBox "Error :" & Err.Description, vbCritical, "Printing File..."
End Sub

Usage

Create a Form with a Command Button and a ListBox.

Private Sub Command1_Click()
    PrintTXTFile "C:\logon.reg"
End Sub

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.