Solved

print document

Posted on 2001-06-26
9
239 Views
Last Modified: 2012-05-04
How can i print a document i.e wordpad rtf doc from vb
0
Comment
Question by:leachim
  • 4
  • 3
  • 2
9 Comments
 
LVL 3

Expert Comment

by:shankarkrupa
ID: 6227858
Project Name=PrintFile.exe

Selecting a standard.exe project....
Go to the components.....

Select the Microsoft richtextbox control
 (May be in the path directory \system\richtext32.ocx)

Then, do as follows:

Include a button---(Command1)
Include a richtextbox control---(richtextbox1)
Include another button -----(command2)


Here are the functions::::


private sub command1_Click()
richtextbox1.loadfile inputbox("Enter the rtf file name")
end sub

private sub command2.click()
RichTextBox1.SelStart = 1
RichTextBox1.SelPrint
end sub

That is all...........
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 6228153
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

Dim lngResult As Long
lngResult = ShellExecute(Me.hwnd,"Print",strFile,0&,0&,vbMinimized)

where strFile is the full path to your  file



0
 

Author Comment

by:leachim
ID: 6228467
iboutchkine
looks good but i cant declare it in my general declaration for some reason?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 

Author Comment

by:leachim
ID: 6230235
shankarkupra
nearly worked but error on the RichTextBox1.SelPrint
"argument not optional"
?
0
 

Author Comment

by:leachim
ID: 6230259
iboutchkine
works only on txt files
i need it to work on rtf doc files
thanks
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 6231140
leachim, it works perfectly on doc files. Right now I tried to print word document. Here the exact code:
Option Explicit
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

Private Sub Command1_Click()
Dim lngResult As Long
lngResult = ShellExecute(Me.hwnd, "Print", "c:\a.doc", 0&, 0&, vbMinimized)
MsgBox "done"
End Sub
0
 
LVL 3

Accepted Solution

by:
shankarkrupa earned 10 total points
ID: 6238786
Oh, very sorry leachim...I should have told this before...It expects a long argument...

It is nothing but your printer's hDC..just do change that line as follows:

RichTextBox1.SelPrint Printer.hDC

It is just a sort of identity for your program to the printer...That selPrint function takes any hDC...For example,you can even give the form.hWnd and see that all the text is printed in your form...


0
 

Author Comment

by:leachim
ID: 6238865
thats it nice one shankarkrupa
0
 
LVL 3

Expert Comment

by:shankarkrupa
ID: 6241976
Thank you...
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

830 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