Solved

print document

Posted on 2001-06-26
9
202 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 62
MS Access - Capture pressed key onclick 4 41
Modifying Conditional Format from VBA code 3 59
Zip Folders Using Chilkat Routines 1 58
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

790 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