Solved

print document

Posted on 2001-06-26
9
194 Views
Last Modified: 2010-05-02
How can i print a document i.e wordpad rtf doc from vb
0
Comment
Question by:leachim
9 Comments
 

Accepted Solution

by:
THuynh earned 10 total points
ID: 6229756
try this:

ShellExecute(handle, "print", path_to_folder, NULL, NULL, SW_SHOWNORMAL);

0
 

Author Comment

by:leachim
ID: 6230247
THuynh
looks promising.... only doesn't there need to be a declare statement before it?
0
 

Expert Comment

by:mhowling
ID: 6230324
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

0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

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

comes back syntax error
any further suggestions?
0
 

Expert Comment

by:mhowling
ID: 6231470
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.
0
 
LVL 4

Expert Comment

by:wileecoy
ID: 6236159
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?)
0
 

Author Comment

by:leachim
ID: 6238898

HERES THE ANSWER CURTESY OF SHANKARKUPRA


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

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7139839
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
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7178879
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

786 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