?
Solved

print document

Posted on 2001-06-26
9
Medium Priority
?
221 Views
Last Modified: 2010-05-02
How can i print a document i.e wordpad rtf doc from vb
0
Comment
Question by:leachim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Accepted Solution

by:
THuynh earned 40 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 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…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 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