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 "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
Then use it like this:
Dim X As Long
X = ShellExecute(formname, "Print", 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.'
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.