Solved

print document

Posted on 2001-06-26
9
172 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
Comment Utility
try this:

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

0
 

Author Comment

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

Expert Comment

by:mhowling
Comment Utility
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
 

Author Comment

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

comes back syntax error
any further suggestions?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Expert Comment

by:mhowling
Comment Utility
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
Comment Utility
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
Comment Utility

HERES THE ANSWER CURTESY OF SHANKARKUPRA


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

0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
Comment Utility
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now