Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How I print to printer? 1

Status
Not open for further replies.

joseprez

Vendor
Sep 7, 2002
19
0
0
PA
How in VB6, print my file "Receives.txt" to the printer.

 
One method is this:

Dim appWord As Word.Application
Dim docWord As Word.Document

Set appWord = CreateObject("Word.Application")
Set docWord = appWord.Documents.Open(App.Path + "\Receives.txt")

' Start print job.
docWord.PrintOut True

' Run this loop until the printing is done.
' This prevents the application from closing while the print job is still
' in progress.
Do While appWord.BackgroundPrintingStatus <> 0
Loop

' Close the Word Document
docWord.Close
' Close the Word Application
appWord.Quit

' Clear out variables, prevent memory leak.
Set docToPrint = Nothing
Set appWord = Nothing

This will open your Word application, open the text file, print the document. Keep Word open long enough to print the document. Close document and Word after printing is done.

If you don't want to use Word, you can use the shell() function to call notepad. You should be able to find documentation on the shell() function. I would sway you to use the first option if the computer that's going to be running this program has MS Office installed. Obviously if it does not, you'll have to go another route.
 
The other way is to use ShellExecute API. In a module declare the API:

Public Declare Function ShellExecute Lib &quot;shell32.dll&quot; Alias &quot;ShellExecuteA&quot; (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


Then use it like this:

Dim X As Long
X = ShellExecute(formname, &quot;Print&quot;, FileName, 0&, 0&, 3)

where formname refers to the parent form (usually Me.Hwnd) and Filename contains the name of the file to Print

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top