Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Printing A text file

Posted on 2000-04-14
9
Medium Priority
?
146 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:R_N_WARD
9 Comments
 

Author Comment

by:R_N_WARD
ID: 2717026
I need some help, any help, FAST!
0
 

Author Comment

by:R_N_WARD
ID: 2717078
I need some help, any help, FAST!
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2717103
Private Sub cmdPrint_Click()
Printer.Print Text1.Text
Printer.EndDoc
End Sub
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:R_N_WARD
ID: 2717117
AzraSound, I need to print A File like C:\Textfile.txt
0
 

Author Comment

by:R_N_WARD
ID: 2717121
AzraSound, I need to print A File like C:\Textfile.txt
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 105 total points
ID: 2717137
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
 

Author Comment

by:R_N_WARD
ID: 2717156
Thanks for the advice, AzraSound.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2717168
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
 
LVL 7

Expert Comment

by:BarryTice
ID: 2717192
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question