Link to home
Start Free TrialLog in
Avatar of leachim
leachim

asked on

print document

How can i print a document i.e wordpad rtf doc from vb
ASKER CERTIFIED SOLUTION
Avatar of THuynh
THuynh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leachim
leachim

ASKER

THuynh
looks promising.... only doesn't there need to be a declare statement before it?
Heres the declare statement for the function and constants

Private Const SW_MAXIMIZE = 3
Private Const SW_MINIMIZE = 6
Private Const SW_NORMAL = 1

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

Avatar of leachim

ASKER

mhowling
after incorporating your declare statements
ShellExecute(Handle, "print", "c:\testfig.doc", Null, Null, SW_SHOWNORMAL);

comes back syntax error
any further suggestions?
Sorry about that leachim.

Okay the problem is with the Null's try replacing them with "" i.e

ShellExecute(Handle, "print", "c:\testfig.doc", "", "", SW_SHOWNORMAL)

ALTERNATIVELY
------------

Heres another way of doing it.

Private Sub Command1_Click()
    Dim WordObj As Object
   
    Set WordObj = GetObject("C:\testtemp\vbtest.doc")
   
    WordObj.Activate
    WordObj.PrintOut
   
    WordObj.Close
   
    Set WordObj = Nothing
End Sub

NOTE This is Late Binding.  It can be done with early binding if you want by setting the project to reference Microsoft Word x.0 then rewritting the above as

Private Sub Command1_Click()
    Dim WordObj As New Document
   
    Set WordObj = WordObj.Application.Documents.Open("C:\TestTemp\vbtest.doc")

   
    WordObj.Activate
    WordObj.PrintOut
   
    WordObj.Close
   
    Set WordObj = Nothing
End Sub

These will print the document without the user ever realising that it has used Word.  Whereas the ShellExecute method opens word prints the document and then closes word again.
mhowling,

looks good, however, I have a question.

Will this work with just the application distributed files? (will it work if the workstation that this is distributed on doesn't have Word or doesn't have that version of Word?)
Avatar of leachim

ASKER


HERES THE ANSWER CURTESY OF SHANKARKUPRA


RichTextBox1.LoadFile "whatever"
RichTextBox1.SelStart = 1
RichTextBox1.SelPrint Printer.hDC

Avatar of DanRollins
Hi leachim,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept THuynh's comment(s) as an answer.

leachim, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Comment from expert accepted as answer

Computer101
E-E Moderator