Solved

print document

Posted on 2001-06-26
9
232 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
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: 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

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