Solved

print document

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

Author Comment

by:leachim
ID: 6230235
shankarkupra
nearly worked but error on the RichTextBox1.SelPrint
"argument not optional"
?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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 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…

911 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

23 Experts available now in Live!

Get 1:1 Help Now