Printing A text file

On Command, I want to My program to print a Text file to my printer. (I have muliple printers on a network). How do I send my text file to one of these printers?
R_N_WARDAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
AzraSoundConnect With a Mentor Commented:
just load the file into a text box or a richtextbox.  richtextbox has its own load and print methods built in.

richtextbox.loadfile "filename and path"
richtextbox.SelPrint (Printer.hDC)
0
 
R_N_WARDAuthor Commented:
I need some help, any help, FAST!
0
 
R_N_WARDAuthor Commented:
I need some help, any help, FAST!
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
AzraSoundCommented:
Private Sub cmdPrint_Click()
Printer.Print Text1.Text
Printer.EndDoc
End Sub
0
 
R_N_WARDAuthor Commented:
AzraSound, I need to print A File like C:\Textfile.txt
0
 
R_N_WARDAuthor Commented:
AzraSound, I need to print A File like C:\Textfile.txt
0
 
R_N_WARDAuthor Commented:
Thanks for the advice, AzraSound.
0
 
wsh2Commented:
Adda Common Dialog control to your project (CommonDialog1) and copy and paste the following in:

<----- Code Begin ----->

   Dim strPrint As String
   Open "c:\autoexec.bat" For Binary As #1
   strPrint = Space$(LOF(1) - 1)
   Get #1, , strPrint
   Close (1)
   
   CommonDialog1.CancelError = True
   On Error GoTo PrintCancel
   CommonDialog1.ShowPrinter
   Printer.Print (strPrint)
   Printer.EndDoc
   On Error Goto 0

PrintCancel:

<----- Code End ----->
0
 
BarryTiceCommented:
You've got two other ways (at least).

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
    ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Sub Command1_Click()

ShellExecute me.hwnd, "Print", "File.txt", "", "C:\Path\SubPath\", &H01

End Sub


' or

Public Sub Command2_Click()

Dim intFile as Integer
Dim strText as String

intFile = FreeFile
Open "C:\Path\SubPath\File.txt" For Input As #intFile
Do While Not EOF(intFile)
    Line Input #intFile, strText
    Printer.Print strText
Loop
Close #intFile
Printer.EndDoc

End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.